dongyuli4538 2012-04-13 17:07
浏览 8
已采纳

PHP IF条件建议需要

I'm using emails as username to login into a site being developed, now if a user updates their email from the profile page, how can i make sure that my email checking statement doesnt catch the user's email as already registered in the database.

the page profile

 /* Now we will store the values submitted by form in variable */
           $fullname=$_POST['fullname'];
           $dob=$_POST['dob'];
           $address=$_POST['address'];
           $myusername=$_POST['myusername'];           
           $telephone=$_POST['telephone'];

$queryuser=mysql_query("SELECT * FROM customer WHERE email='$myusername' ");
$checkuser=mysql_num_rows($queryuser);

if($checkuser != 0) 
{ 
$Merr[]='» Sorry this email is already registered!';
}
else {$insert_user=mysql_query("UPDATE CUSTOMER SET SYNTAX HERE");

Now these are the fields in question;

(name, dob, address, email, telephone) VALUES ('$fullname', '$dob', '$address', '$myusername', '$telephone')

As you can see if the user changes the login email then the syntax checks for the email being submitted against the database, however if the user leaves the email unchanged he will get the error because it is found in the database.

I was thinking of something like;

if($checkuser != 0) {
  if($myusername == $_POST['myusername'])
   (...dont show error.) 

but my php skills are limited. can anyone advise please, thanks

  • 写回答

3条回答 默认 最新

  • dongtui8593 2012-04-13 17:17
    关注
    /* Now we will store the values submitted by form in variable */
    $myusername=$_POST['myusername'];           
    
    
    $queryuser=mysql_query("SELECT username FROM customer WHERE email='$myusername' ");
    $checkuser=mysql_num_rows($queryuser);
    
    /*Mysql_fetch_row will select the first row from the query and put it into a 
    multidimensional array. As you only want 1 e-mail associated with one user the query
    should only ever select one row anyway.  */
    $row = mysql_fetch_row($queryuser);
    
    if($checkuser != 0) 
    { 
          if($row[0] != $SESSION['username'])
          {
          //ERROR
          }
    
    }
    else {
    //Update details
    }
    

    That way you can just submit the e-mail along with any other inputs and if the e-mail hasn't changed you wont need to do anything.

    Also you've said your posting the logged in users username. I would imagine you would actually want to be using sessions to do that.

    And don't forget to escape the POST data for security.

    Also the INSERT INTO should that not be an update statement if they are updating their e-mail address?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?