Jump to content

help! trying to create PHP search form and it's not working


kelseyirene

Recommended Posts

I've been struggling with this all afternoon. The code seems correct, no problems are turning up, I'm connecting to the database, but the search isn't yielding results that I know are there. My table is fairly simple, it's basically a list of the books I own... my columns are 'num' 'title' 'author_first' 'author_last' 'isbn' and 'read'. Ideally, I'd like to be able to search for any keyword in any of the columns, but for now I just want to figure out how to do the search form.

 

Here's the code I used for the form:

 

<form method="post" action="search.php">

<div align="center">

<table border="0" cellpadding="0" cellspacing="0">

<tr>

<td bordercolor="#000000">

<p align="center">

<select name="num" size="1">

<option value="title">Title</option>

<option value="telephone">Author Last</option>

<option value="birthday">ISBN</option>

</select> <input type="text" name="search" size="25">  <br>

Search database: <input type="submit"></p>

</td>

</tr>

</table>

</div>

</form>

 

--

 

and this is the form I used for search.php:

 

<center>

<table border="1" cellpadding="5" cellspacing="0" bordercolor="#000000">

<tr>

<td width="60"><b>num</b></td>

<td width="100"><b>title</b></td>

<td width="70"><b>author last</b></td>

<td width="150"><b>isbn</b></td>

</tr>

<tr>

<td>

<?

$con = mysql_connect("localhost","username","password") or die(mysql_error());

 

mysql_select_db("my_db",$con);

 

?>

 

<?

//error message (not found message)begins

$XX = "No Record Found, to search again please close this window";

//query details table begins

$query = mysql_query("SELECT * FROM TitleInfo WHERE $num LIKE '%$search%' LIMIT 0, 50");

while ($row = @mysql_fetch_array($query))

{

$variable1=$row["num"];

$variable2=$row["title"];

$variable3=$row["author_last"];

$variable4=$row["isbn"];

//table layout for results

 

print ("<tr>");

print ("<td>$variable1</td>");

print ("<td>$variable2</td>");

print ("<td>$variable3</td>");

print ("<td>$variable4</td>");

print ("</tr>");

}

//below this is the function for no record!!

if (!$variable1)

{

print ("$XX");

}

//end

?>

</table>

</center>

 

 

</html>

 

--

 

help!! what am I doing wrong?

Link to comment
Share on other sites

As harkly says you don't manually assign a value to $search. Since your form has an input that has a name attribute of 'search' it would seem you are relying on register_globals being enabled, which it may not be.

Link to comment
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.