-1

ユーザーが行ったフォーム入力を送信しようとしていますが、数値を入力すると、ユーザーが入力した値ではなく 0 がデータベースに入力されます。助けてください

これが私の


<?php
//once the submit the button is submited it connects to the database
if(isset($_POST['submitGrades'])) {
include ("account.php") ;
( $dbh = mysql_connect ( $hostname, $username, $password ) )
                or    die ( "Unable to connect to MySQL database" );

mysql_select_db( $project ); 
// this part checks the value of "id" that it exist in another table first
$id = mysql_real_escape_string($_POST['id']);
$result = mysql_query("SELECT id FROM newstudent WHERE id = '$id'");

if (mysql_num_rows($result)) {
    // Go ahead and insert everything in table1
    $data = array(
        'id' => $_POST['id'],
        'subject' => $_POST['subject'],
        'gradeone' => $_POST[gradeone], //this stores as 0 in the database
        'gradetwo' => $_POST[gradetwo], //this stores as 0 in the database
        'gradethree' => $_POST[gradethree], //this stores as 0 in the database
    );

    // Make sure all the data is safe for entry into the database
    foreach ($data as $key => $val) {
        $data[$key] = "'" . mysql_real_escape_string($val) . "'";
    }
    $fields = implode(', ', array_keys($data));
    $values = implode(', ', array_values($data));
    $result = mysql_query("INSERT INTO grades ($fields) VALUES ($values)");
    echo 'Your grades were submited.';
} else {
    echo 'The Student does not exist. Please Enter the student first.';
}}?>

これがHTMLコードです

<form id="grades" action="php/grades.php" method="post" OnSubmit="setTimeout('reset_form()', 200); return true" >
<label>STUDENT ID</label>
<input type="text" placeholder="PLEASE ENTER STUDENT ID" class="input" maxlength="9" name="id" id="id"></br>
    <label>SUBJECT</label>
    <select class="input" name="subject" id="subject">
        <option>Select One</option>
        <option>Math</option>
        <option>Chemistry</option>
        <option>English</option>
        <option>Physics</option>
        <option>French</option>
        <option>Computer Science</option>
        <option>Network</option>
    </select></br>
        <label>GRADE 1</label>
        <input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradeone" id="gradeone"></br>
        <label>GRADE 2</label>
        <input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradetwo" id="gradetwo"></br>
        <label>GRADE 3</label>
        <input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradethree" id="gradethree"></br>
        <input type="submit" value="Submit" name="submitGrades" id="submitGrades"/> </form>

前に言ったように、ユーザーがグレード 1、グレード 2、グレード 3 に値を入力すると、mysql データベースに 0 として保存される理由を理解するのに助けが必要です...

4

3 に答える 3

0

さて、私を混乱させるのはこの部分です

$result = mysql_query("SELECT id FROM newstudent WHERE id = '$id'");

のみを選択idしている場合、 の値をどのように取得していますか$_POST['gradeone'], $_POST['gradetwo'],$_POST['gradethree'] , $_POST['subject']。これらすべての列が選択されているクエリは他にありません。

于 2013-10-04T06:39:25.750 に答える