Last active
September 12, 2017 11:19
-
-
Save boazcstrike/fa0b11eef9755de4be243eb88be1e141 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//this is for an example of an SQL select statement, creating a "preparation" for the SQL statement to be executed | |
$select_userq = $link->prepare("SELECT * FROM login_user WHERE username = ? AND password = ?"); | |
//next is we bind the parameters to make sure which variables are to be inserted in the question marks | |
$select_userq->bind_param("ss",$username,$crypted_password);//before the first comma, is i for integer or s for string, etc. | |
//password encryption | |
$crypted_password = crypt($password, "randomcharacters!@#%^*()"); | |
//this simply executes the prepared SQL statement | |
$select_userq->execute(); | |
$insert_userq = $link->prepare("INSERT INTO login_user (username, password) VALUES (?,?); | |
$insert_userq->bind_param("ss",$username,$crypted_password); | |
$insert_userq->execute(); | |
//this passes the variables that is selected from the select statement | |
$select_userq->bind_result($user_id, $username, $crypted_password); | |
//stores the temporary results to $select_userq | |
$select_userq->store_result(); | |
//count number of rows, count if username and password exists | |
$if_exists = $select_userq->num_rows; | |
if($if_exists>0) | |
{ | |
while($row = $select_userq->fetch()) //fetch | |
{ | |
//we binded the results from line 20 | |
echo "ID:" . $user_id; | |
echo "Uname:". $username . "<br>"; | |
echo "Pass:" . $crypted_password . "<br>"; | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment