When accessing my database, I have a user filling out a form, and on the landing page, the posted values are used in the resulting MySQL query.
$query = mysql_query("SELECT pass FROM database WHERE user='$_POST[user]'");
However, for one reason or another, MySQL does not like it when I use the $ _POST variable in a command, and it only works if I define (for example) $user = $_POST['user'];, and then put $ user directly in the SQL command.
On the other hand, I can use the $ _POST values in INSERT statements where column names are not required:
$query = mysql_query("INSERT INTO database VALUES ('foo', 'bar', '$_POST[user]'");
If I try the INSERT statement where the attributes are defined (e.g. user='foo'), the same problem appears.
What am I doing wrong in my SQL query, which results in a command error at startup, but works with a specific formatting method for the INSERT command?
Hopefully this is not "hard luck, it looks like you need to assign all of your published values." Heh.
source
share