Reputation: 51
For my website I am generating unique value email and random code as login, so when the user login with the above email and code, so I need to echo the details of that user only.
Example: In my database im having first name, last name, mobile number, email, code. So if the user login with email and code, I have to Echo all details as first name, last name, mobile number
In my case how to use exact query to echo all the details by email and code.
$sql = 'select firstname, lastname, mobileno from clients where code=; & email=
If (is_array($row = $db->queryRow($sql)))
Echo($firstname, $lastname, $mobileno) = $row;
Please help.
Upvotes: 1
Views: 122
Reputation: 16132
$code = $_POST['code'];
$email = $_POST['email'];
$sql = $db->prepare("SELECT firstname, lastname, mobileno FROM `clients` WHERE code = ? AND email = ?");
$sql->execute(array($code, $email));
$results = $sql->fetchAll(PDO::FETCH_ASSOC);
foreach ($results as $row) {
echo $row['firstname'].'<br>';
echo $row['lastname'].'<br>';
echo $row['mobileno'].'<br>';
}
Upvotes: 2
Reputation: 2035
This is the html to login:
<form action="" method="POST">
<input name="email" type="email"><br>
<input name="code" type="text"><br>
<input name="submit" type="submit" value="login">
</form>
This will be different for each user as he has his own details to login...
Submitting the form:
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$code = $_POST['code'];
$sql = mysql_query("SELECT firstname, lastname, mobileno FROM `clients` WHERE code = '$code' AND email = '$email'");
while ($row = mysql_fetch_array($sql)) {
echo $row['firstname'].'<br>';
echo $row['lastname'].'<br>';
echo $row['mobileno'].'<br>';
}
}
Upvotes: 0