php - Using an Array to verify login and password -
i can array of user file when access db. missing how use array verify input user. array contains piece of data need capture , use on later page?
here code generates array , part of foreach trying work. on right track?
$sql = "select * users;"; $result = mysql_query($sql, $dbc); //run query if ($result) { $html .= '<h2>result found </h2>'.php_eol; //grab arrays result for($i = 0; $i < mysql_num_rows($result); $i++) { $array = mysql_fetch_array($result, mysql_assoc); print_r($array); foreach ('username' $inputusername){ echo 'password'; } } } else { $html .= '<h2>error: '.mysql_error().' </h2>'; }
so, instead of fetching users in database iterating on 1 one check passwords, can tell mysql "give me password of user has username of exampleuser" this:
$username = "exampleuser"; $sql = "select `password` users `username` = '$username';"; $result = mysql_query($sql, $dbc); //run query if ($result) { $row = mysql_fetch_assoc($result); $password = $row['password']; echo '<h2>result found '.$password.'</h2>'.php_eol; } else { echo '<h2>no user found, or error: '.mysql_error().' </h2>'; }
on side note pleace notice mysql_ functions deprecated, left them in there keep code intact , show minor differences.
Comments
Post a Comment