开发者

Query doesn't work

I get the following error message when I try this query:

$query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())";

You have an error in your SQL syntax. Check th开发者_Go百科e manual that corresponds to your MySQL server version for the right syntax to use near

(18, , 'Y', NOW())' at line 1

Everything in my code works except this line. I know it has to do with $_POST array variable, but i don't know the correct syntax.

If you need more code, I will be happy to include it.


Your use of single quotes around $i is wrong:

$query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())";

This will cause $i to be taken literally instead of the value of $i being used (which is what I assume you need).

This should work:

$query .= "($tid, {$_POST['type'][$i]}, 'Y', NOW())";


If you want better, help, show the code that's sending the post variables (probably a form or AJAX request).

But your problem may lie here:

$query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())";

The post would evaluate to something like $_POST['type']['1']. You probably want $_POST['type'][1].

So try this:

$query .= "($tid, {$_POST['type'][$i]}, 'Y', NOW())";


As already mentioned.

$query .= "($tid, {$_POST['type']['$i']}, 'Y', NOW())";

Should read

$query .= "($tid, {$_POST['type'][$i]}, 'Y', NOW())";

Curious why you have "{ }" in use.

That said, you should always avoid typing variables from $_GET or $_POST straight into code to be used in queries, or any other aspects of your site.

You really should get into the habit or passing the variable via something you have pre-determined.

Not to mention, will you be escaping these variables prior to running the sql query.

Take a look at

http://php.net/mysql_real_escape_string http://php.net/pdo.quote

If you have the time, investigate pdo.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜