Hi!

can someone help me to figure out with this code?

<form method="POST" action="insert.php">
<input type="checkbox" name="id[]" value="32">Article #32<br>
<input type="checkbox" name="id[]" value="38">Article #38<br>
<input type="checkbox" name="id[]" value="45">Article #45<br>
<input type="checkbox" name="id[]" value="59">Article #59<br>
<input type="hidden" name="referer" value="123">
<!-- This is the ID of the "referring" article -->
<input type="Submit">
</form>

$ref = $_POST['referer'];
$query = 'INSERT INTO related_articles (id, referer) VALUES (' .
implode(", $ref), (", $_POST['id']) . ", $ref)";
$result = mysql_query($query)
or die('Could not execute INSERT query');

for an instance the user will checked articles #32 and #59
here's the query that is going to be executed:

INSERT INTO related_articles (id, referer)
VALUES (32, 123), (59, 123);

my question is how to configure this code:

$ref = $_POST['referer'];
$query = 'INSERT INTO related_articles (id, referer) VALUES (' .
implode(", $ref), (", $_POST['id']) . ", $ref)";
$result = mysql_query($query)
or die('Could not execute INSERT query');

to query like this one:

INSERT INTO detail (Quantity, Unit, Description)
VALUES (1, pcs, etc..), (4, pcs, etc...);

I really need your help with this guys because i'm stuck with this for an hour.
Thanks..

Try this.

$qty = $_POST['qty'];
$unit = $_POST['unit'];
$desc = $_POST['desc'];

$query = "INSERT INTO detail (Quantity, Unit, Description) VALUES ";
for ($i=0;$i<=sizeof($qty)-1;$i++){
	$query = $query."({$qty[$i]},{$unit[$i]},$desc[$i]), ";
}
$query=substr($query,0,-2);
echo $query;

Please note the qty,units and desc would be array's coming in from the previous page.

Greetings!
Hi sudeepjd!, Thank you for sharing your idea, now i figured it out what's the problem with my code..

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.