Jump to content



Photo

Fulltext Searches

fulltext search search multiple tables searches

  • Please log in to reply
23 replies to this topic

#21 lalarukh12

lalarukh12

    Advanced Member

  • Members
  • PipPipPip
  • 63 posts

Posted 12 August 2012 - 3:46 AM

thanks for your reply.
now i am using the following code to search a single table when user enters a keyword.
<html>
<head>
<title>Search the Database</title>
</head>

<body>


<html>
<head>
<title>Search the Database</title>
</head>

<body>

<form action="searchlast.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>


</body>
</html>



</body>
</html>
<?php
echo $_POST['term'];



require_once ('mysqli_connect.php');





$term = $_POST['term'];

$sql = mysql_query("select * from designers where first_name like '%$term%'");





$term = $_POST['term'];

$sql = mysql_query("select * from designers where first_name like '%$term%'");

while ($row = mysql_fetch_array($sql)){
echo 'designer_id: '.$row['designer_id'];
echo '<br/> First Name: '.$row['first_name'];
echo '<br/> Last Name: '.$row['last_name'];
echo '<br/><br/>';
}

?>

and getting the following errors
Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 30

Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 40

Notice: Undefined index: term in C:\xampp\htdocs\searchlast.php on line 48

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\searchlast.php on line 52

do someone know the solution please?
  • 0

#22 HartleySan

HartleySan

    Advanced Member

  • Members
  • PipPipPip
  • 2,862 posts
  • LocationColumbus, OH USA

Posted 12 August 2012 - 5:23 AM

You can't just blindly try to grab values from the $_POST array. You have to first test whether the $_POST array has any values in it to begin with, which will only be the case when the form is submitted. Try putting a majority (if not all) of your PHP code within the following if condition:

if (isset($_POST['term']))

  • 0

#23 margaux

margaux

    Advanced Member

  • Members
  • PipPipPip
  • 451 posts

Posted 12 August 2012 - 5:23 AM

As an aside It would help if you proofread your post before posting as you appear to have duplicate tags and queries. Also it would help if you inserted your code between code tags (there is an icon you can use on the edit bar).

Here's why you're getting the undefined index error: The first time your script is run, the form has not been submitted so the $_POST array will not have any values. You need to start with a conditional to check for this index
if (isset($_POST['term'])) {
You're using the improved version of mysql (mysqli) to connect to the database and the old version mysql to make your query.

Here is a simplified version of what I think you're trying to do using mysqli. You may need to change the $dbc variable to match what is in your mysqli_connect.php file
<form action="searchlast.php" method="post">
Search: <input type="text" name="term" /><br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
if (isset($_POST['term'])) {
echo $_POST['term'];
require_once ('mysqli_connect.php');
$term = $_POST['term'];
$query = "select * from designers where first_name like '%$term%'";
$result = mysqli_query($dbc, $query);
while ($row = mysqli_fetch_array($result)){
echo 'designer_id: '.$row['designer_id'];
	 echo '<br/> First Name: '.$row['first_name'];
	 echo '<br/> Last Name: '.$row['last_name'];
	 echo '<br/><br/>';
}
}
?>

  • 1

#24 Jaepee

Jaepee

    Advanced Member

  • Members
  • PipPipPip
  • 69 posts
  • LocationSan Jose Ca

Posted 12 August 2012 - 5:01 PM

I was gonna post but I like Margauxs' post ...
  • 0





Also tagged with one or more of these keywords: fulltext search, search, multiple tables, searches