Hi all, I have a small script that should process the data from a previous page and enter it into the database and then redirect the user. It is redirecting the user but not updating the information in the database. Any thoughts or ideas would be appreciated as always!
Not only is your query prone to SQL injection, youāre not even quoting your associative keys, forcing PHP to assume that undefined constant is actually a string⦠(to translate, itās not $_POST[prodname], itās $_POST[āprodnameā]);
āLocationā header expects FULL URL, not path, itās terrible to redirect users like that, some browser might not understand it.
And what Guido said, echo the query with variables and run it within some MySQL GUI so you can see the result.
So itās recognizing that the form has been submitted, as guido said, print/echo (never usually use echo i must say xD) the query, to see what is being sent.
Although I always encase my variables in double quotes so:
$updateData = mysql_query("UPDATE order_products SET product_name='$_POST[prodname]' WHERE id='$_GET[row]'");
To;
$updateData = mysql_query("UPDATE order_products SET product_name='" . $_POST[prodname] . "' WHERE id='" . $_GET[row] . "'");
The OP gives the impression heās passing one through the query string as well as using _POST from a submitted form.
Which is what confused me.
I may have been a bit too presumptuous
Hey guys/gals, apologies, I did not realize I had any replies to this post. Iām using $_GET as I dragging up data from the database with the option to update that data. Itās part of a Point of Sale Intranet Iām working on. With regards to reformatting the query string, I will get on that straight away, appreciate the help and advice on here, cheers all
Incidentally, if I use double quotes on my query string such as mysql_query(āUPDATE users SET names='ā.$_POST[ānameā].ā'ā); would I need not to use the mysql_real_escape_string?
No. $_REQUEST is evil, for the simple reason that you just donāt know where any of its values are coming from, which makes it very error-prone. Itās slightly less evil than register_globals but it comes pretty close.
Itās not in the code you posted, so that means that the code you posted isnāt the production code. So it will be impossible to tell you where the bugs in your production code are.
Not sure I fully agree that ā$_REQUEST is evilā. I would classify it as convenient more than evil. As long as all external data is fully scrubbed, I donāt think it matters. Iād say register_globals is certainly evil as it actually creates variables in global scope. Obviously a personal preference issue.