Hi, im having trouble with a mysql insert, please help! I want to insert multiple rows into a database table. There are only 2 columns in the table - 'id' and 'used'. I want the id field to auto increment I want the used column to all have 'NO' inserted. I want the amount of rows to be specified by user input to a form. Ive tried to use the limit function but im getting an error. Im thinking Limit only works on selects? Can anyone shed any light on this. This is what i tried: if (isset($_POST['submit'])) { $code_qty = $_POST['code_qty']; include("includes/db_connect.inc.php"); $sql = " INSERT INTO single_promo SET used = 'NO' LIMIT=$code_qty"; PHP:
LIMIT, SET and INSERT aren't meant to be used together - you've totally misunderstood something. What exactly are you trying to achieve ?
at first in mysql create AUTO_INCREMENT field (id) then, two way - in php create a cycle, in each iteration insert new row in table (insert into table (field_name) values ("NO")) - in mysql (not best way ), you can create script for multiple row inserts insert into table (field_name) values ("NO"), ("NO"), ... ("NO"), ("NO");
i just want to insert multiple rows into a table, automatically dependant on how many rows the user wants to insert
this worked a treat! $code_qty = $_POST['code_qty']; $i=0; while ($i <= $code_qty) { $sql = "INSERT INTO single_promo SET used = 'NO'"; $result = @mysql_query($sql,$connection) or die(mysql_error()); $i++; } PHP: cheers for you input guys!