How do I search for a certain ID in a database using php?
I’m making a php script that will get a user-inputted number and then search a MySQL database for that ID then read all the information off of that row. I’m sure there is a function that does this since looping through thousands of entries is so inefficient. I’m just not sure what it is.
user input form:
<form action="http://www.yoursite.com/php_script.php" method="post">
<input type="text" name="user_id">
<input type="submit" value="Submit">
</form>
php_script.php
<?php
$user_id = $_POST['user_id'];
$con = mysql_connect("localhost", "DB_USER","DB_PASS");
mysql_select_db("USER_ID_TABLE", $con);
$result = mysql_query("SELECT * FROM USER_ID_TABLE WHERE user_id = ‘$user_id’");
while($row = mysql_fetch_array($result))
{
echo ‘
<TABLE>
<TR>
<TD>’.$row['column_a'].’</TD>
<TD>’.$row['column_b'].’</TD>
<TD>’.$row['column_c'].’</TD>
</TR>
</TABLE>
‘;
}
?>
if you are going to be retrieving sensitive information (social security #s, credit cards etc) then i recommend getting a professional to do it and have them look into SSL certificates