Jump to content

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?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.