[英]how to get primary key id of a registered email
i have a problem on my project im currently working on and this is my Email controller i want to get the id of an email registered in my database 我的项目目前正在进行中有问题,这是我的电子邮件控制器,我想获取在我的数据库中注册的电子邮件的ID
if ($this->getRequest()->isPost()) {
$formData = $this->getRequest()->getPost();
if ($form->isValid($formData)) {
$imail = $form->getValue('email');
$users = new Application_Model_DbTable_Users();
$row = $users->fetchRow($users->select('uid')->where('email = ".$imail."'));
/* if ($row == 1) {
$token = uniqid(mt_rand(), true);
$userpass = new Application_Model_DbTable_Password();
$userpass->addToken($uid , $token);
} else { $this->view->errorMessage = "Email not registered"; }
*/
//$this->emailAction();
}
i just need to get the id to be able to shift to my next function but i cant do it also i think this might be unrelated but i did this on pure php and it works fine 我只需要让id能够转移到我的下一个功能,但我也不能这样做我认为这可能是无关的但我在纯PHP上做了这个并且工作正常
if (isset($_POST['submit'])) {
$email = $_POST['email'];
$getemail = mysql_query("SELECT `uid` FROM `users` WHERE `email` ='$email'");
$resemail = mysql_num_rows($getemail);
if ($resemail == 0) {
echo "Email id is not registered";
}
$token = uniqid(mt_rand(), true);
$getoken = mysql_query("INSERT INTO `password_recovery` (`uid`,`token`) VALUES ((SELECT `uid` FROM `users` WHERE `email` = '$email'),'$token') ");
how can i do this logic in zendframework 1 thank you 我怎么能在zendframework中做这个逻辑1谢谢
Solution of Jehad Keriaki is correct, but unsafe. Jehad Keriaki的解决方案是正确的,但不安全。 Use prepared statement syntax instead, for example:
使用预准备语句语法,例如:
$row = $users->fetchRow($users->select('uid')->where('email = ?', $imail));
It will protect you from SQL injection attack. 它将保护您免受SQL注入攻击。
Try changing 尝试改变
$row = $users->fetchRow($users->select('uid')->where('email = ".$imail."'));
to 至
$row = $users->fetchRow($users->select('uid')->where('email = "$imail"'));
I think the issue is with the dots, which you still can use as: 我认为问题在于点,你仍然可以用作:
$row = $users->fetchRow($users->select('uid')->where('email = "'.$imail.'"'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.