Note that there are some explanatory texts on larger screens.

plurals
  1. POI'm using PHP and need to Insert into sql using a while loop
    primarykey
    data
    text
    <p>I'm after a little help. I have a page for a user to input upto 10 different rows of information. Dispatch details. I have created a page with my form using a loop.. </p> <pre><code>&lt;?php session_start(); require("config.php"); require("header.php"); $db = mysql_connect($dbhost, $dbuser, $dbpassword); mysql_select_db($dbdatabase, $db); ?&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/br&gt; &lt;form action="insertdispatch.php" method="post"&gt; &lt;body&gt; &lt;center&gt; &lt;table&gt; &lt;tr&gt; &lt;td&gt;&lt;center&gt;&lt;b&gt;Ref&lt;/td&gt; &lt;td&gt;&lt;b&gt;&lt;center&gt;Date&lt;/td&gt; &lt;td&gt;&lt;b&gt;&lt;center&gt;Service&lt;/td&gt; &lt;td&gt;&lt;b&gt; &lt;center&gt;Tracking&lt;/td&gt; &lt;/tr&gt; &lt;?php $index = 1; $name = 1; while($index &lt;= 10){ ?&gt; &lt;td&gt;&lt;input type="text" name="transno&lt;?php echo $index;?&gt;" id="transno&lt;?php echo $index;?&gt;" /&gt; &lt;/td&gt; &lt;td&gt;&lt;input type="text" name="date&lt;?php echo $index;?&gt;" id="date&lt;?php echo $index;?&gt; "/&gt; &lt;/td&gt; &lt;td&gt;&lt;select name = "service&lt;?php echo $index;?&gt;"&gt;&lt;?php $viewsql = "SELECT * FROM dispatch_service ORDER BY service ASC"; $viewresult = mysql_query($viewsql); while($row = mysql_fetch_assoc($viewresult)){ ?&gt; &lt;option value=&lt;?php echo $row['service'] ;?&gt;&gt; &lt;?php echo $row['service'] ;?&gt;&lt;/option&gt; &lt;?php } echo "&lt;/select&gt;";?&gt; &lt;td&gt;&lt;input type="text" name="tracking&lt;?php echo $index;?&gt;" id="tracking&lt;?php echo $index;?&gt;"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;?php $index ++; }?&gt; &lt;center&gt; &lt;td&gt;&lt;input type="submit" value="Add Product" /&gt; &lt;/form&gt; &lt;/center&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/center&gt; &lt;center&gt;&lt;a href='javascript:history.back(1);'&gt;Back&lt;/a&gt; &lt;/body&gt; &lt;/html&gt;` </code></pre> <p>I have 10 of each text box, the name of the text box adds the value of index to the end. (with my limited coding experience I am very pleased with myself) so I go to the insertdispatch.php page and the plan is to insert each of these values into my table... now...I have no clue... and I cannot seem to figure out how I am going to do this...</p> <p>I think I will need to use a loop again.. but I can't seem to figure out how I am going to call each of the $_POST values. I don't really want to use 10 different insert statements, as the form may increase in size. here is what I have so far..</p> <pre><code>&lt;?php session_start(); require("config.php"); $db = mysql_connect("localhost","root",""); if (!$db) { do_error("Could not connect to the server"); } mysql_select_db("hbt",$db)or do_error("Could not connect to the database"); $index = 1; while($index &lt;= 10){ $insertsql = "INSERT into dispatch (trans_no, date, service, tracking) values ()"; mysql_query($insertsql); $index ++; } //header("Location: " . $config_basedir . "home.php"); ?&gt; </code></pre> <p>I am not looking for anyone to finish the coding for me, but any tips would be grateful! :)</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