Jump to content

Recommended Posts

I am still getting error..

$Var=$_POST['limit'];
$VarCount = mysql_real_escape_string($Var);
$query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT $VarCount ORDER BY datetime DESC ") or die(mysql_error());

//error
//You have an error in your SQL syntax;...check near LIMIT...etc

 

If I replace $VarCount(user defined) by 2,3,4(any integer).....it is working. Any ideas?

 

 

Link to comment
https://forums.phpfreaks.com/topic/179905-solved-mysql-limit-error/
Share on other sites

I'm a fan of using quotes...

 

$query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT " . $VarCount . " ORDER BY datetime DESC ") or die(mysql_error());

 

And the people who have posted below are absolutely correct.  Limit needs to be at the end....

set your sql to a variable and then echo it to make sure it looks like it should.

$VarCount=mysql_real_escape_string($_POST['limit']); 
$sql="SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) AND LIMIT $VarCount ORDER BY datetime DESC "
echo $sql;
$query=mysql_query($sql); 

Only Taqui and Mike worked...

 

if(isset($_POST['Submit']))
{
$VarCount=mysql_real_escape_string($_POST['limit']);
$query = mysql_query("SELECT * FROM test WHERE id NOT IN (SELECT id FROM test1) ORDER BY datetime DESC LIMIT $VarCount") or die(mysql_error());

 

Thanks

 

 

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.