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