I’ve built this little script that searches a table in my database, but for the life of me I can’t seem to find anywhere on how to display the table information if someone only searches for the email. I want to be able to search for only the email and have it display all the information for that email address from the database. Any thoughts?
<?php
$profile = $_POST["profile"];
mysql_connect ("", "", "");
mysql_select_db ("");
$query = "SELECT * FROM `profile` WHERE `email`='$email' and `about`='$about' and
`age`='$age' and `sex`='$sex' and `website`='$website'";
$result = mysql_query ($query);
if ($result) {
while($row=mysql_fetch_row($result))
{
echo $row[0],$row[1],$row[2];
}
}else{
}
?>
<form action="profile.php" method="post">
<input type="text" name="search"><br>
<input type="submit">
Non-numeric field must be enclosed with single quotes in a query.
EDIT:
In above code-snippet you have single
textfield and asubmit buttonso you can use"search"field value to search on any one database field at a time.If you want to search on email then sql query will be:
You can use
ORoperator to search on one or more field:You can use LIKE operator to search a string