Jump to content

any one no whats wrong here ? help plz


nbbcj

Recommended Posts

hi all me again :(

 

i have this bit of code


mysql_connect($db_hostname,$db_username,$db_password);
@mysql_select_db($db_database) or die( "Unable to select database");

$whereClauses = array();
if(isset($_GET['bi'])) { $whereClauses[] = "bi=1"; }
if(isset($_GET['print'])) { $whereClauses[] = "print=1"; }
if(isset($_GET['online'])) { $whereClauses[] = "online=1"; }

$query = "SELECT * FROM  `project` ORDER BY  `project`.`position` ASC ";
if(count($whereClauses))
{
    $query .= " WHERE " . implode(" AND ", $whereClauses);
}

 

with this error msg

There was a problem with the SQL query: 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 'WHERE online=1' at line 3

 

I get this kinda error a lot as im still learning is there any way to better find out whats going wrong i use

error_reporting(E_ALL);
ini_set('display_errors', '1');

at the start of my scripts but it dont tell me a lot. i can work  out it some thing to do with the $whereClauses  as the page displays ok on show all.

 

Im bit stumped here not even sure what to call the prob is it sql query error or php array problem :(

 

thanks for any help 

Link to comment
https://forums.phpfreaks.com/topic/262578-any-one-no-whats-wrong-here-help-plz/
Share on other sites

echo the query after the implode and paste it up for us to see. Also try removing the space in front of the word WHERE

"WHERE " . implode(//etc...

 

I'm not 100% on this, but I think your Where clause needs to come before the order by.

 

yer im thinking that to :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.