View Full Version : Where Clause doesnt work
phpmysqlcoder
01-09-2007, 09:47 PM
hey everyone
new to this forum
im creating a website with a mysql database. ive jus got started.
im havin a few problems
i have a product table and i execute a simple query but it doesnt seem to give me any results
heres the query
Select * from product where ProductName = 'Age of Empires III';
the above query doesnt work but this 1 does
Select * from product where ProductName LIKE 'Age%';
im really confused. need help. thanks
whizard
01-09-2007, 10:15 PM
Welcome!
First I would say make sure there actually is a field with the value 'Age of Empires III'.
Secondly, add or die(mysql_error()); to the end of the line where you run your query, something like
$result = mysql_query($query) or die(mysql_error());
That will return any errors you may be getting with the query.
Besides that, it's hard to diagnose anything without seeing a little more code.
HTH,
Dan
phpmysqlcoder
01-09-2007, 10:34 PM
hi whizard
thanks for ur reply
heres the code
$query = "Select * from product where ProductName = 'Age of Empires III'";
$result = mysql_query($query) or die(mysql_error());
while($name_row = mysql_fetch_row($result)) {
print ("$name_row[0] $name_row[1] $name_row[2]<br>\n");
}
i do have the value in my table. when i include the die statement it doesnt give me anything. its jus blank.
look forward to another reply. thanks
also im using mysql version 5 if that helps.
whizard
01-09-2007, 10:49 PM
Your problem is placing superglobals in double quotes.
Change print ("$name_row[0] $name_row[1] $name_row[2]<br>\n");
to
print ("{$name_row[0]} {$name_row[1]} {$name_row[2]}<br>\n");
When you put superglobals ($_GET,$_POST,$_SERVER etc...) inside double quotes, you have to wrap them in {}.
HTH
Dan
phpmysqlcoder
01-09-2007, 10:50 PM
Solved the problem
i was stupid enough to use a mysql management software that i thought was simpler to add and update data.
i think it added tabs or space at the end thats y it was givin me problems. i added a new records using the mysql command line and then tested the code and it worked. sorri 4 the hassle.
phpmysqlcoder
01-09-2007, 10:51 PM
Your problem is placing superglobals in double quotes.
Change print ("$name_row[0] $name_row[1] $name_row[2]<br>\n");
to
print ("{$name_row[0]} {$name_row[1]} {$name_row[2]}<br>\n");
When you put superglobals ($_GET,$_POST,$_SERVER etc...) inside double quotes, you have to wrap them in {}.
HTH
Dan
oh k thanks will definetly use that.
whizard
01-09-2007, 10:53 PM
Glad you got your problem solved!
Dan :thumbsup:
vBulletin® v3.8.2, Copyright ©2000-2012, Jelsoft Enterprises Ltd.