Note that there are some explanatory texts on larger screens.

plurals
  1. POInserted only once in mysql db.
    primarykey
    data
    text
    <p>I have the following code to add data to my database. It seems correct any everything is working fine, however it adds only once to the database and, after that it tells me that the data has been saved into database correctly, but when you want to check it to see if it has been added, I can see that its hasnt been added. </p> <p>insert.php</p> <pre><code>&lt;?php session_start(); $server = ""; $user_name = ""; $password = ""; $database = ""; $id = $_SESSION['id']; $res_name = $_SESSION['username']; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "INSERT INTO [db_table] (ID,name,category,dish_name,explanation,ingredients,price) VALUES ('$id','$res_name','$_POST[cat]','$_POST[dname]','$_POST[about]','$_POST[ing]','$_POST[num]')"; $result = mysql_query($SQL); mysql_close($db_handle); print "Records added to the database"; echo "&lt;BR&gt;"; echo "&lt;a href='newitem.php'&gt;Back to main page&lt;/a&gt;"; } else { mysql_close($db_handle); } ?&gt; </code></pre> <p>and in my html form:</p> <pre><code>&lt;form class="form-inline" action="inser.php" method="post"&gt; &lt;input type="text" id="dname" name="dname" class="input-medium" placeholder="Dish Name"&gt; &lt;?php $server = ""; $user_name = ""; $password = ""; $database = ""; $id = $_SESSION['id']; $res_name = $_SESSION['username']; $_SESSION['id'] = $id; $db_handle = mysql_connect($server, $user_name, $password); $db_found = mysql_select_db($database, $db_handle); if ($db_found) { $SQL = "SELECT category from Category where Rest_ID = '".$id."'"; $result = mysql_query($SQL,$db_handle) or die(mysql_error()); $i = 0; echo "&lt;select id='cat' name='cat'&gt; &lt;option selected='selected'&gt;Select&lt;/option&gt;"; while($row = mysql_fetch_array($result)){ $i = $i + 1; echo "&lt;option&gt;".$i.". $row[category]&lt;/option&gt;"; } echo '&lt;/SELECT&gt;'; } else { mysql_close($db_handle); } //echo $id; ?&gt; &lt;input type="text" id="ing" name="ing" class="input-medium" placeholder="Ingredients"&gt; &lt;input type="text" id="about" name="about" class="input-medium" placeholder="About this food"&gt; &lt;input type="number" id="num" name="num" class="input-medium" onkeypress="return isNumberKey(event)" placeholder="Price"&gt; &lt;button type="submit" class="btn btn-success"&gt;Add&lt;/button&gt; &lt;/form&gt; </code></pre> <p>I cant seem to figure the problem. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    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.
    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