Forum Moderators: coopster
<? $dbcnx = mysql_connect('localhost', 'onoff', 'passwrd');//connect to server
if ($dbcnx){
echo('<p>connected successfully</p>');
}
if (!@mysql_select_db('blast_db')) {//connect to database
exit('<p>Unable to locate the event ' .
'database at this time.</p>');
}
if (mysql_select_db('blast_db')) {//connect to database
echo('<p>Database OK</p>');
}
$form_res = @$_GET['q'] ;
$trimmed = trim($var);
$result = mysql_query('SELECT * FROM leinster WHERE event LIKE "%$form_res%"');
while ($row = mysql_fetch_array($result)) {
echo '<b>' . date( 'jS F Y', $row['timestamp'] ) .'</b>';
echo '<p>' . $row['event'] . '</p>';
echo '<p>' . $row['details'] .'</p>';
}
?>
[edited by: onoff at 4:36 pm (utc) on Aug. 11, 2005]
you could try some of the PHP library threads about PHP and MySQL [webmasterworld.com]
for your specific case I would add some troubleshooting [webmasterworld.com]
construct the query on a line by itself
echo your query to see if it is constructed correctly
you're using the wrong var in your query
get the error from mysql if there is one
$form_res = $_GET['q'];
$trimmed = trim($var);
$sql = "SELECT * FROM leinster WHERE event LIKE '%" . $trimmed . "%'";
echo '<p>query is: ',$sql;
$result = mysql_query($sql) or die ("<p>the query died: " . mysql_error());
while ($row = mysql_fetch_array($result)) {
try that