Jump to content

[SOLVED] What am I doing wrong??


almightyegg

Recommended Posts

I am customising a mysql_query depending on what a user has inserted on the form on the page before but I have an error in my syntax :(

$psyche = $_POST['psyche'];
$psymin = $_POST['psymin'];
$psymax = $_POST['psymax'];

$level = $_POST['level'];
$lvlmin = $_POST['lvlmin'];
$lvlmax = $_POST['lvlmax'];

$lf = $_POST['lf'];
$lfmin = $_POST['lfmin'];
$lfmax = $_POST['lfmax'];

$soc = $_POST['soc'];

$sort = $_POST['sort'];
$order = $_POST['order'];

if($level == TRUE && is_numeric($lvlmin) == TRUE && is_numeric($lvlmax) == TRUE){
$info .= " level >= '$lvlmin' and level <= '$lvlmax'";
}
if($psyche == TRUE && is_numeric($psymin) == TRUE && is_numeric($psymax) == TRUE){
$info .= " psyche >= '$psymin' and psyche <= '$psymax'";
}
if($lf == TRUE && is_numeric($lfmin) == TRUE && is_numeric($lfmax) == TRUE){
$info .= " lifeforce >= '$lfmin' and lifeforce <= '$lfmax'";
}
if($soc == all){
$info .= " clutch >= '0'";
}elseif($soc == notmine){
$info .= " clutch != '{$mem['clutch']}' and clutch > '0'";
}elseif($soc == mine){
$info .= " clutch = '{$mem['clutch']}'";
}elseif($soc == none){
$info .= " clutch = '0'";
}

$info .= " SORT BY $sort $order";


$sel = mysql_query("SELECT * FROM users WHERE$info") or die(mysql_error());

 

 

This is the code the creates the mysql_query ($sel) but it shows:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'psyche >= '-5000' and psyche <= '-2000' clutch = '0' SORT BY level ASC' at line 1

 

Can anybody help me with this??

Link to comment
Share on other sites

assumed it wasnt there as your error statement says:

 

'psyche >= '-5000' and psyche <= '-2000' clutch = '0'

 

anyway try echoing out the sql string and see what you get.. best way to debug when queries dont work:

 

echo "SELECT * FROM users WHERE $info";

 

then copy and paste it and try running that statement in you mySQL GUI(phpmyadmin or whatever you use) and see what errors it gives you..

 

Link to comment
Share on other sites

I had got an error with that, a really stupid one too. Thanks for noticing that but I have another one  :P

 

I echoed it out:

SELECT * FROM users WHERE level >= '1' and level <= '20' and psyche >= '-5000' and psyche <= '-2000' and lifeforce > '-1' and clutch = '0' SORT BY level ASC

 

I can't see problems with it?

 

I editted the code to fix some errors

 

if($level == TRUE && is_numeric($lvlmin) == TRUE && is_numeric($lvlmax) == TRUE){
$info .= " level >= '$lvlmin' and level <= '$lvlmax'";
}else{
$info .= " level != '0'";
}
if($psyche == TRUE && is_numeric($psymin) == TRUE && is_numeric($psymax) == TRUE){
$info .= " and psyche >= '$psymin' and psyche <= '$psymax'";
}else{
$info .= " and psyche != '0'";
}
if($lf == TRUE && is_numeric($lfmin) == TRUE && is_numeric($lfmax) == TRUE){
$info .= " and lifeforce >= '$lfmin' and lifeforce <= '$lfmax'";
}else{
$info .= " and lifeforce > '-1'";
}
if($soc == all){
$info .= " and clutch >= '0'";
}elseif($soc == notmine){
$info .= " and clutch != '{$mem['clutch']}' and clutch > '0'";
}elseif($soc == mine){
$info .= " and clutch = '{$mem['clutch']}'";
}elseif($soc == none){
$info .= " and clutch = '0'";
}

$info .= " SORT BY $sort $order";


$sel = mysql_query("SELECT * FROM users WHERE$info");

Link to comment
Share on other sites

are your fields level etc varchar fields or number fields such as int ..

 

if they are number fields then try without the quotes around the numbers e.g

 

SELECT * FROM users WHERE level >= 1 and level <= 20 and psyche >= -5000 and psyche <= -2000 and lifeforce > -1 and clutch = 0 SORT BY level ASC

 

also have you tried running it directly in your GUI .. do you get any query errors now? ..

 

 

Link to comment
Share on other sites

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.