Jump to content

Recommended Posts

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>

 

Link to comment
https://forums.phpfreaks.com/topic/85116-error-help/
Share on other sites

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."%'";

Link to comment
https://forums.phpfreaks.com/topic/85116-error-help/#findComment-434195
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.