Jump to content

inserting POST variable into sql string.


denoteone

Recommended Posts

I have three pieces of data I need to insert

1. is a post variable named storeid

2.  a value stored in an array named products1

3.  the value of an input from a form the inputs name is the same set by an array

 


for($i=0;$i<20;$i++){
$sql="INSERT INTO price2 (storeID, productID, price) VALUES ('".$_POST['storeid']."','$products1[$i]','".$_POST[$products1[$i]]."')";
	$result = $db->query($sql);

			}

 

Any help would be great.

 

Link to comment
https://forums.phpfreaks.com/topic/195471-inserting-post-variable-into-sql-string/
Share on other sites

Well, what's the problem, besides the lack of escaping and potential SQL injection?

 

for($i=0;$i<20;$i++){
$sql="INSERT INTO price2 (storeID, productID, price) VALUES ('".$_POST['storeid']."','".$products1[$i]."','".$_POST[$products1[$i]]."')";
	$result = $db->query($sql);
			}

I think more what we are asking is, what specifically is the issue? You gave us a code snippet of the query, but nothing else relevant. The issue could be all sorts of places. If we know what is going on, then we know where to look.

 

Is the query not inserting? is it throwing errors? When you echo the query before insertion, what is the result?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.