PDA

View Full Version : mySQL syntax


spam_killer
07-16-2008, 08:24 PM
Hello guys !!

Can anyone help me to figure out the correct syntax to adapt the $variable into this script ??

mySQL table is: example
________________________________________
ID User Job Age
1 Micheal Mechanic 21
2 Polo Doctor 22
3 Harry Fireman 21
----------------------------------------------

<?php

mysql_connect("localhost", "administrator", "12345") or die(mysql_error());
echo "Connected to MySQL<br />";
$result = mysql_query("SELECT * FROM example WHERE Age LIKE '%2' ")
or die(mysql_error());
while($row = mysql_fetch_array( $result )) {
echo $row['Job']." - ".$row['Age']. "<br />";
}
?>


The above script is valid and I got the result as:

________________________
Job Age
Mechanic 21
Fireman 21
----------------------------

But, when I tried to replace the '%2' with $variable:

$variable = 2;
$result = mysql_query("SELECT * FROM example WHERE Age LIKE '%2' ")

then I got ERROR..
What is the need to replace the variable into the script ?
What is the ERROR come from ?


**actually the $variable contains value from GET or POST action from html form

**Please help me..

_Aerospace_Eng_
07-16-2008, 08:36 PM
What was the exact error your received? Post the code that processes the $variable part as well as the query that uses that.

spam_killer
07-16-2008, 09:14 PM
I just figure it out to adapt the variable.. Thanks to you..It just simple..
What should I do is just to get into the error messages and find the error code..

Actually I didn't receive any payment to do this..I'm just interested in learning PHP and mySQL database as nowadays it is the most popular open source in the world.. Thanks guy..!!

_Aerospace_Eng_
07-16-2008, 10:00 PM
That wasn't necessarily aimed at you. It's in my signature.