I'm trying to search for rows that contain a certain string. For that, I'm using the following query:
SELECT `1` as 'msgTime',
`4` as 'shout'
FROM log.shout_log' WHERE shout LIKE '".$name."' ORDER BY 1 DESC
I'm getting $name
from:
$name = $_GET['name'];
My url: ./shout_log.php?name=Montz
But I encounter the following error:
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 shout LIKE 'Montz' ORDER BY 1 DESC' at line 1
Everything is to return a message that this name shouted.
$ms = $row['shout'];
echo '<span style="color:blue;">'.$ms.'</span>';
Whats wrong with my query?
EDIT:
$name = "%".$_GET['name']."%";
$info = mysql_query("SELECT `1` as 'msgTime', `4` as 'shout' FROM log.shout_log WHERE 'shout' LIKE '$name'") or die(mysql_error());
echo '<table><tr><th>Data</th><th>Menssagem</th></tr>';
while($row = mysql_fetch_object($info)){
echo '<span style="color:blue;">'.htmlspecialchars($row->shout).'</span>';
}
echo '</table>';