The code is this:

<html>
<head>
<link rel=stylesheet type=text/css href=style.css>
<title>
Search Results
</title>
</head>
<body>
<?php include("header.php"); ?>
<center>
<div class=indexboxlarge2>
<?php
SESSION_start();
include("dbcon.php");
$searchresult = $_POST['result'];
dbcon();
$query = mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%$searchresult%' OR WHERE 2_name LIKE '%$searchresult%'") or die(mysql_error());
$total = mysql_num_array($query);
if ($total!=0) {
while ($row = mysql_fetch_array($query)) {
echo $row["1_name"];
echo " ";
echo $row["2_name"];
echo "<br>";
echo "<br>";
}
}
else	
{
	echo "Sorry there results to display.";
}

?>
</div>
</center>
</body>
</html>

i get this 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 2_name LIKE '%"the search result%'' at line 1

Were i wrote the search result is what the user input is.

Any help will be happily accepted,

jakx12

Member Avatar for diafol

You may do well to escape your variable or "brace" it, e.g.

mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%{$searchresult}%' OR WHERE 2_name LIKE '%{$searchresult}%'")

OR

mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%" . $searchresult . "%' OR WHERE 2_name LIKE '%" . $searchresult . "%'")

There are also issues with the HTML - it seems to be poorly formed.

thanks, but i get this now!

Fatal error: Call to undefined function mysql_num_array() in /home/a8896310/public_html/searchresult.php on line 18

thanks but i get this now:

Fatal error: Call to undefined function mysql_num_array() in /home/a8896310/public_html/searchresult.php on line 18

Member Avatar for diafol

There's no such function as that. Do you want mysql_num_rows or mysql_fetch_array ?

I assume that this is not a new error, it's just that pHp stopped before this previously due to another error (your ' OR ' troubles).

ok so i have tried most things here is the modded code, but i now get this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/a8896310/public_html/searchresult.php on line 18

the code:

<html>
<head>
<link rel=stylesheet type=text/css href=style.css>
<title>
Search Results
</title>
</head>
<body>
<?php include("header.php"); ?>
<center>
<div class=indexboxlarge2>
<?php
SESSION_start();
include("dbcon.php");
$searchresult = $_POST['result'];
dbcon();
$query1 = mysql_query("SELECT * FROM 'user_info' WHERE '1_name' LIKE '%{$searchresult}%' OR WHERE '2_name' LIKE '%{$searchresult}%';");
$total = mysql_num_rows($query1);
if ($total != 0) {
while ($row = mysql_fetch_array($query1)) {
echo $row["1_name"];
echo " ";
echo $row["2_name"];
echo "<br>";
echo "<br>";
}
}
else	
{
	echo "Sorry there results to display.";
}

?>
</div>
</center>
</body>
</html>

sorry about this but its really annoying me!

Member Avatar for diafol
mysql_query("SELECT * FROM 'user_info' WHERE '1_name' LIKE '%{$searchresult}%' OR WHERE '2_name' LIKE '%{$searchresult}%';");

You've quoted your fieldnames - don't! Also you've done WHERE twice! And you've got double ';'!

mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%{$searchresult}%' OR 2_name LIKE '%{$searchresult}%'");

Try that.

The code is this:

<html>
<head>
<link rel=stylesheet type=text/css href=style.css>
<title>
Search Results
</title>
</head>
<body>
<?php include("header.php"); ?>
<center>
<div class=indexboxlarge2>
<?php
SESSION_start();
include("dbcon.php");
$searchresult = $_POST['result'];
dbcon();
$query = mysql_query("SELECT * FROM user_info WHERE 1_name LIKE '%$searchresult%' OR WHERE 2_name LIKE '%$searchresult%'") or die(mysql_error());
$total = mysql_num_array($query);
if ($total!=0) {
while ($row = mysql_fetch_array($query)) {
echo $row["1_name"];
echo " ";
echo $row["2_name"];
echo "<br>";
echo "<br>";
}
}
else    
{
    echo "Sorry there results to display.";
}

?>
</div>
</center>
</body>
</html>

i get this 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 2_name LIKE '%"the search result%'' at line 1

Were i wrote the search result is what the user input is.

Any help will be happily accepted,

jakx12

You not supposed to have 2 'WHERE'
try this:

WHERE 1_name LIKE '%{$searchresult}%' OR 2_name LIKE '%{$searchresult}%'

and you may want to try to use backticks (key above the tab key) to quote the field names like this:
1_name

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.