脚本宝典收集整理的这篇文章主要介绍了php – 使用预准备语句检查数据库中是否已有电子邮件,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
//if email is equal to an email already in the database,display an error message if(MysqL_num_rows(MysqL_query("SELECT * From users WHERE email = '".MysqL_real_escaPE_string($_POST['email'])."'"))) { echo "<p class='red'>Email is already registered wITh us</p>"; } else { // missing code? }
// create MysqLi object $MysqLi = new MysqLi(/* fill in your connection info here */); $email = $_POST['email']; // might want to validate and sanitize this First before passing to database... // set query $query = "SELECT COUNT(*) From users WHERE email = ?" // PRepare the query,bind the VARiable and execute $stmt = $MysqLi->prepare( $query ); $stmt->bind_param( 's',$email ); $stmt->execute() // grab the result $stmt->Store_result(); // get the count $numRows = $stmt->num_rows(); if( $numRows ) { echo "<p class='red'>Email is already registered with us</p>"; } else { // .... }
此链接也可以帮助您:
http://www.php.net/manual/en/mysqli.quickstart.prepared-statements.php
以上是脚本宝典为你收集整理的php – 使用预准备语句检查数据库中是否已有电子邮件全部内容,希望文章能够帮你解决php – 使用预准备语句检查数据库中是否已有电子邮件所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。