Note that there are some explanatory texts on larger screens.

plurals
  1. POInsert Data from Checkbox and Textbox in DB
    primarykey
    data
    text
    <p>I've created two php files with code for an order form for a cafeteria and the correspronding lines of code for inserting the posted values in my database. Here I present them. </p> <p>CODE FOR addorder_form.php</p> <pre><code>**&lt;?php db_connect(); $cats=array("Kafedes", "Rofhmata", "Pota", "Snack/Glyka"); $arrlength=count($cats); for($i=0;$i&lt;$arrlength;$i++) { $sql = mysql_query('SELECT title FROM products WHERE cname="'.$cats[$i].'"') or die(mysql_error()); echo '&lt;div id="main_content"&gt;'; echo "&lt;h4 style=color:#800000&gt; ".$cats[$i]."&lt;/h4&gt;"; echo "&lt;br /&gt;"; while($row = mysql_fetch_array($sql, MYSQL_BOTH)){ echo "&lt;div id='center' style='align:center'&gt;"; echo "&lt;input style='text-align:right;' type='checkbox' action='addorder.php' name='products[]' value='".$row["title"]."'&gt;".$row["title"]; echo '&lt;/div&gt;'; echo ' &lt;div id="center_side" style="float:right"&gt;&lt;form "method="post" action="addorder.php"&gt;&lt;input type="text" size="4" padding-left="0.2em" name="quantity"/&gt;'; echo '&lt;/div&gt;'; echo '&lt;/div&gt;'; echo '&lt;br /&gt;'; } } echo '&lt;form name="addorder" method="" action="addorder.php" onclick="addorder.php"&gt;'; echo '&lt;input type="submit" value="Add order" style="float: right;"&gt;&lt;br/&gt;'; echo '&lt;/form&gt;'; ?&gt;** </code></pre> <p>CODE FOR addorder.php</p> <pre><code>**&lt;?php include_once("buzzcafe_fns.php"); do_html_header(""); $quantity = ''; $title = ''; if (isset($_POST['quantity']) &amp;&amp; isset($_POST['products'])) { if(isset($_POST["Submit"])) { $quantity = $_POST['quantity']; $title = $_POST['products']; if($_POST["Submit"] == "Submit") { for ($i=0; $i&lt;sizeof($title); $i++) { db_connect(); $insertOrder = mysql_query("INSERT INTO orders VALUES('".$title[i]."','".$quantity."')")or die(mysql_error()); } echo "Record inserted"; } } } ?&gt;** </code></pre> <p>When I run them I have non any syntax errors, though it does not work. As far as the db_connect() is set in the buzzcafe_fns.php file I've included and it is checked that works properly. How can I make my "INSERT INTO" work? </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.
    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