$mok3 Posted January 9, 2008 Share Posted January 9, 2008 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 'LIKE '%Greg%'or names_last LIKE '%Greg%'' at line 1 i dont understand y it not work any1 can help? <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Results</title> </head> <body bgcolor="#000000" text="#FFFFFF"> <?php if(!$_POST['submit']) { echo 'Please go back and enter a search query'; exit; } else { $search = $_POST['submit']; } //connecting to the database require 'config.php'; @$dbconn = mysql_connect ($hostname, $mysql_login, $mysql_password); If (!$dbconn){ echo ' PHP could not connect to the database' . mysql_error(); exit; } else { echo ' A successesful connection was established'; } //Successful connection starts search mysql_select_db(dbpease12, $dbconn); $query = "SELECT * fROM Names". "where names_first LIKE '%".$search."%'". "or names_last LIKE '%".$search."%'"; $result = mysql_query($query) or die(mysql_error()); ?> <table width="534" border="1" cellpadding="10"> <tr> <td width="78">ID</td> <td width="148">First Name </td> <td width="115">Last Name </td> </tr> <?php while ($row = mysql_fetch_assoc($query))?> <?php { ?> <tr> <td><?php echo $row['names_id']; ?> </td> <td><?php echo $row['names_first']; ?></td> <td><?php echo $row['names_last']; ?></td> </tr> <?php } ?> </table> <?php //Closes connection mysql_close($dbconn); ?> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/85116-error-help/ Share on other sites More sharing options...
Stooney Posted January 9, 2008 Share Posted January 9, 2008 You need to add the necessary spaces in the query so things don't run together...(notice the added spaces at the beginning of the last 2 lines) $query = "SELECT * FROM Names". " where names_first LIKE '%".$search."%'". " or names_last LIKE '%".$search."%'"; Quote Link to comment https://forums.phpfreaks.com/topic/85116-error-help/#findComment-434195 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.