Note that there are some explanatory texts on larger screens.

plurals
  1. POForm submited with php stores 0s
    primarykey
    data
    text
    <p>I am trying to submit a form entry done by the user but when the numbers are entered, 0 is entered into the database instead of the user entered value. Help please </p> <p>Here is my </p> <hr> <pre><code>&lt;?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' =&gt; $_POST['id'], 'subject' =&gt; $_POST['subject'], 'gradeone' =&gt; $_POST[gradeone], //this stores as 0 in the database 'gradetwo' =&gt; $_POST[gradetwo], //this stores as 0 in the database 'gradethree' =&gt; $_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 =&gt; $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.'; }}?&gt; </code></pre> <p>And this is the HTML code</p> <pre><code>&lt;form id="grades" action="php/grades.php" method="post" OnSubmit="setTimeout('reset_form()', 200); return true" &gt; &lt;label&gt;STUDENT ID&lt;/label&gt; &lt;input type="text" placeholder="PLEASE ENTER STUDENT ID" class="input" maxlength="9" name="id" id="id"&gt;&lt;/br&gt; &lt;label&gt;SUBJECT&lt;/label&gt; &lt;select class="input" name="subject" id="subject"&gt; &lt;option&gt;Select One&lt;/option&gt; &lt;option&gt;Math&lt;/option&gt; &lt;option&gt;Chemistry&lt;/option&gt; &lt;option&gt;English&lt;/option&gt; &lt;option&gt;Physics&lt;/option&gt; &lt;option&gt;French&lt;/option&gt; &lt;option&gt;Computer Science&lt;/option&gt; &lt;option&gt;Network&lt;/option&gt; &lt;/select&gt;&lt;/br&gt; &lt;label&gt;GRADE 1&lt;/label&gt; &lt;input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradeone" id="gradeone"&gt;&lt;/br&gt; &lt;label&gt;GRADE 2&lt;/label&gt; &lt;input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradetwo" id="gradetwo"&gt;&lt;/br&gt; &lt;label&gt;GRADE 3&lt;/label&gt; &lt;input type = "text" placeholder="OUT OF 100" class="input" maxlength="3" name="gradethree" id="gradethree"&gt;&lt;/br&gt; &lt;input type="submit" value="Submit" name="submitGrades" id="submitGrades"/&gt; &lt;/form&gt; </code></pre> <p>As I said before i need help in figuring why when user enters values into gradeone, gradetwo, gradethree it stores into the mysql database as 0's... </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload