Page 1 of 1
sql_query syntax error
Posted: Fri Dec 12, 2008 4:01 pm
by Jim_Bo
Hi,
The follwoing peice of code:
Code: Select all
$query = mysql_query('SELECT * FROM stock
INNER JOIN manufacturers on manufacturers.mid=stock.mid
INNER JOIN colors on colors.cid=stock.cid
INNER JOIN sizes on sizes.sid=stock.sid
INNER JOIN products on products.pid=stock.pid
WHERE stock.stid IN (';
foreach($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY stock.stid ASC';
$result = mysql_query($query);
Gives the an error on this line:
Code: Select all
Parse error: syntax error, unexpected ';' in /home
Cant figure it out..
Thanks
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 4:05 pm
by requinix
Let's remove the query and see what's left:
Code: Select all
$query = mysql_query('query';
foreach($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY stock.stid ASC';
$result = mysql_query($query);
You see the problem now?
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 4:13 pm
by Jim_Bo
I dont sorry..
I kno that this works..
Code: Select all
$query = 'SELECT * FROM stock WHERE stid IN (';
foreach($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY stid ASC';
$result = mysql_query($query);
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 4:42 pm
by requinix
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 5:52 pm
by Jim_Bo
Im still not seing it..
What i dont get is the fact that this work fine..
Code: Select all
$query = 'SELECT * FROM stock WHERE stid IN (';
foreach($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY stid ASC';
$result = mysql_query($query);
The only difference between that and the first post is the query..
Maybe some extra clues then ?
Im lost ahve spent hours on such a small issue
Thanks
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 6:01 pm
by Chris Corbyn
You can't split function calls across multiple statements. It's already been pointed out to you that this won't work. You're terminating your function call before you've finished making it (semicolon forms end of statement).
Also, change your foreach() followed by substr() for a simple implode(',', $_SESSION['cart']).
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 7:54 pm
by Jim_Bo
Im lost..
Can I get a bit more example code to get on the right track please..
Thanks
Re: sql_query syntax error
Posted: Fri Dec 12, 2008 8:54 pm
by novice4eva
hehe he simply doesn't see it, well happens
Code: Select all
$query = mysql_query('SELECT * FROM stock
INNER JOIN manufacturers on manufacturers.mid=stock.mid
INNER JOIN colors on colors.cid=stock.cid
INNER JOIN sizes on sizes.sid=stock.sid
INNER JOIN products on products.pid=stock.pid
WHERE stock.stid IN (';
tasairis and chris were trying to say that you have called mysql_query('your query without well a closing bracket but also an incomplete query'; It should have been
Code: Select all
$query = 'SELECT * FROM stock
INNER JOIN manufacturers on manufacturers.mid=stock.mid
INNER JOIN colors on colors.cid=stock.cid
INNER JOIN sizes on sizes.sid=stock.sid
INNER JOIN products on products.pid=stock.pid
WHERE stock.stid IN (';
Re: sql_query syntax error
Posted: Mon Dec 15, 2008 3:04 pm
by Jim_Bo
Doh... So simple
Thanks