Using XAMPP – (latest version – basic – installer) on my computer running XPHome
I want to be able to test php scripts locally before going live on Web Server.
My Database – david
My Table – contacts
My Fields – id, first, last, phone, cell, fax, email, web
I want a search box on an html page or php page that I can type in the last (name) of a person and if there is a match in the “contacts” table then it will display all the fields for that person.
I have this set up already:
Indexes: last FULLTEXT None last
I have tried seven or eight tutorials so far and none of them have worked for me. I get all kind of error messages from T-string to unexpected this or that errors. I think most of the script tutorials were written for earlier versions of mysql and php, which may not be compatible with what I have. I don’t want to buy a search program for my database, but it’s kind of looking that way.
I tried using this but it displays all of the database:
This on a seperate html page that calls the script below
<form name=”form” action=”search.php” method=”get”>
<input type=”text” name=”$keyword” size=”45″ />
<input type=”submit” name=”Submit” value=”Search” />
</form>
The above calls this script
//search.php
<?
$username=”root”;
$password=”passwd”;
$database=”david”;
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
$query = (“SELECT * FROM contacts WHERE last LIKE ‘$keyword%'”);
$result = mysql_query($query) or die(mysql_error());
$num=mysql_numrows($result);
mysql_close();
$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,”first”);
$last=mysql_result($result,$i,”last”);
$phone=mysql_result($result,$i,”phone”);
$cell=mysql_result($result,$i,”cell”);
$fax=mysql_result($result,$i,”fax”);
$email=mysql_result($result,$i,”email”);
$web=mysql_result($result,$i,”web”);
?>
<center>
<table width=”90%” cellspacing=”2″ cellpadding=”0″>
<!–<tr><td colspan=”2″><font face=”Arial” size=”2″><? echo “$id”; ?></font></td></tr>–>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Name:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “<b>$first $last</b>”; ?></font></td>
</tr>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Phone:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “$phone”; ?></font></td>
</tr>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Cell:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “$cell”; ?></font></td>
</tr>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Fax:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “$fax”; ?></font></td>
</tr>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Email:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “$email”; ?></font></td>
</tr>
<tr>
<td align=”right” width=”10%><font face=”Arial” size=”3″>Website:</font></td>
<td width=”90%><font face=”Arial” size=”3″> <? echo “$web”; ?></font></td>
</tr>
<tr><td style=”border-top:1px solid #666″ colspan=”2″> </td></tr>
</table>
</center>
<?
$i++;
}
?>