2016-05-26 5 views
0
私は現在、2つの以上の主題のチェックボックスをカチカチして、データベースに私は困難を見つけることだ、私の現在のスクリプトを提出するユーザーを必要とするプロジェクトに取り組んでいます

とPHPでのデータベース・フィールドに値をチェックしますそれはYで最初のチェックボックスを挿入するだけですが、私が達成したいのは、ユーザーが例えば、科学および数学の場合は、データベースフィールドにScience,Mathematicsとして挿入する必要があります。挿入倍数は、Dreamweaverの

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "main_form")) { 
    $insertSQL = sprintf("INSERT INTO regis (email, write_exam) VALUES (%s, %s)", 
         GetSQLValueString($_POST['email'], "text"), 
         GetSQLValueString(isset($_POST['written_tests']) ? "true" : "", "defined","'Y'","'N'")); 

    mysql_select_db($database_sample, $sample); 
    $Result1 = mysql_query($insertSQL, $sample) or die(mysql_error()); 
} 

HTML

<form id="subject_form" action="user.php"> 
<input name="subject" type="checkbox" id="subject" value="Science" /> 
     Science &nbsp; 
     <input name="subject" type="checkbox" id="subject" value="Mathematics" /> 
     Mathematics&nbsp; 
</form> 
+0

あなたは、チェックボックスのHTMLコードを表示してくださいすることができますか? – Mujahidh

答えて

0

編集:

  • あなたは '科学' と '数学' の両方の値を含む[]配列の対象に名前の件名で、フォームのチェックボックスを変更する必要があります。次にチェックされる被写体[]配列要素を格納するためのSQL insergコードを変更し、そして

    $selectedSubjects = implode(',', $_POST['subject']);

を作成し、DBに$ selectedSubjects値を挿入します。

  • はあなたにHTMLの変更を検討:

<form id="subject_form" action="user.php"> <input name="subject[]" type="checkbox" id="subject" value="Science" /> Science &nbsp; <input name="subject[]" type="checkbox" id="subject" value="Mathematics" /> Mathematics&nbsp; </form>

+0

どうすればいいですか?私はPHPには新人だし、スクリプトにフレーズを入れることができるのだろうかと疑問に思っている。 – neiza

+0

あなたが使用しているHTMLフォームを投稿してください。私はあなたに例を示すでしょう – Taras

+0

私は質問を編集しました – neiza