<?php
include "db.php";
$var = @$_POST['find'];
//check for empty string and display a message.
if($var == ""){
echo "<p>Please input a valid 6-digit ID number</p>";
exit;
} else {
$searchMember = "SELECT * FROM $tablename WHERE id='$var'";
$numresults=mysql_query($searchMember);
$numrows=mysql_num_rows($numresults);
if($numrows == 1){
echo $searchMember['displayname'];
} else if ($numrows == 0){
echo "<p>Sorry, we couldn't find anything that matches your input. Try again?</p>";
}
}
?>
I've included information to connect to database in db.php. And here's how the form looks like:
<body>
<?php
include "db.php";
include "searchSystem.php";
?>
<form name="search" method="post" action="searchSystem.php">
Input a 6-digit ID number: <input type="text" name="find" />
<input type="submit" name="search" value="Search" />
</form>
So there's a column in my table which has 6digit ID of users. We want to let them search their friends' ID number and look at their profile.
So this is what I have just wrote:
<?php
include "db.php";
$var = isset($_POST['find']) ? $_POST['find'] : '';
//check for empty string and display a message.
if($var == ""){
echo "<p>Please input a valid 6-digit ID number</p>";
exit;
} else {
$searchMember = $db->query("SELECT * FROM $tablename WHERE id='$var'");
$row_count = $searchMember->row_count();
$result =$searchMember->fetchALL(PDO::FETCH_ASSOC);
if($row_count == 1){
echo $result['displayName'].' '.$result['id'];
} else if ($row_count == 0){
echo "<p>Sorry</p>";
}
}
?>
Still doesn't work :(