Jump to content

PHP Simple Search


dnienhaus

Recommended Posts

I am trying to make a simple search for an employee database that just needs to search the partnumber and then return a few fields but i can't get it to work. Any help would be greatly appreciated. Thanks..

It jumps straight to this "Search string is empty. Go back and type a string to search."

Heres the form:

[code]<html>
<head><title>Searching...</title>
</head>
<body bgcolor=#ffffff>
<h1>Searching the Database</h1>
<form method="post" action="search.php">
<table width=90% align=center>
<tr><td>search for:</td><td><input type=text name='search' size=60 maxlength=255></td></tr>
<td></td><td><input type=submit></td></tr>
</table>
</form>
</body>
</html>[/code]


Heres the search.php


[code]<?php
$username="edit";
$password="edit";
$database="engineering";


mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");

if($search)
{
$query="SELECT * FROM Assembly WHERE PARTNUMBER='$search'";
$result=mysql_db_query($query);

if($result)
{
echo "Here are the results:<br><br>";
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#00FFFF><b>Creation Date</b></td>
<td align=center bgcolor=#00FFFF><b>Creator</b></td>
<td align=center bgcolor=#00FFFF><b>Nomenclature</b></td>
<td align=center bgcolor=#00FFFF><b>OBID</b></td>
<td align=center bgcolor=#00FFFF><b>Part Number</b></td>
</tr>";

while ($r = mysql_fetch_array($result)) { // Begin while
$CREATIONDATE = $r["CREATIONDATE"];
$CREATOR = $r["CREATOR"];
$NOMENCLATURE = $r["NOMENCLATURE"];
$OBID = $r["OBID"];
$PARTNUMBER = $r["PARTNUMBER"];
echo "<tr>
<td>$CREATIONDATE</td>
<td>$CREATOR</td>
<td>$NOMENCLATURE</td>
<td>$OBID</td>
<td><b>$PARTNUMBER</b></td></tr><br><br><hr>";
} // end while
echo "</table>";
} else { echo "problems...."; }
} else {
echo "Search string is empty. <br> Go back and type a string to search";
}

?>[/code]
Link to comment
Share on other sites

and better to write this line

[code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER='$search'";[/code]

like this

[code=php:0]$query="SELECT * FROM Assembly WHERE PARTNUMBER='" . $_POST['search'] . "'";[/code]

i mean use $_POST :) mybe you register_globals is off in php.ini
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.