Searching a Database

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Bogey
Forum Commoner
Posts: 34
Joined: Sat Nov 10, 2007 5:51 pm

Searching a Database

Post by Bogey »

I need to make a script that searches a database... The following is what I got to do that...

Code: Select all

<form action="testing.php" method="post">
<label for="sname">Search for:</label><br />
<input type="text" name="sname" id="sname" />
<input type="submit" name="submit4" value="submit" /€> <input type="reset" name="reset" value="reset" />
</form>
<?php
  $sname = $_POST['sname'];

  if(!empty($_POST['submit']))
  {
    $result2 = mysql_query("SELECT Name,Gender,birthday,secretquestion,secretanswer,Level FROM user WHERE Name='$sname'");

$tsv  = array();
$html = array();
while($row = mysql_fetch_array($result2, MYSQL_NUM))
{
   $tsv[]  = implode("\t", $row);
   $html[] = "<tr><td bgcolor=\"#EEEEEE\">" .implode("</td><td bgcolor=\"#FFFFFF\">", $row) .              "</td></tr>";
   $htmm = "<br />" . implode("</td><td>", $row) ."<br />";
}

$tsv = implode("\r\n", $tsv);
$html = '<div style="overflow: auto; height: 500px;"><table border="1" width="100%"><tr><td bgcolor="#FFCC00">Name</td><td bgcolor="#FFCC00">Gender</td><td bgcolor="#FFCC00">Birthday</td><td bgcolor="#FFCC00">Secret Question</td><td bgcolor="#FFCC00">Secret Answer</td><td bgcolor="#FFCC00">Level</td></tr>' . implode("\r\n", $html) . '<br /></table></div>';



//echo $tsv;
echo $html;

echo '<table><tr><td>'. $row .'</td></tr></table>';
  }
The only problem is that I don't see the results... why? I assume that it doesn't let me have a variable in the SELECT statement and that is driving me NUTS because other sites do it somehow... I looked at examples and still can't figure out the problem... I looked through numerous numbers of tutorials on databases... retrieving stuff from databases and such and still can't figure out my problem... I really need help on this. Please.
Post Reply