出现意外的#34;语法错误"在我的PHP代码中

时间:2014-04-06 09:12:39

标签: php

我真的坚持这个问题。我怎样才能使它工作?它从电子邮件中选择用户并通过电子邮件重新发送密码。

我在第45行遇到错误但找不到它:

  

解析错误:语法错误,第45行/home/xxxxxx/public_html/xxxx/email.php中的意外'不'(T_STRING)

这是我的代码:

    <?php

$host="localhost"; // Host name - update all those fields
 $username="xxxxx"; // Mysql username
  $password="xxxx"; // Mysql password 
  $db_name="xxxxxx"; // Database name

//Connect to server and select databse. 
mysql_connect("$host", "$username", "$password")or die("cannot connect to server"); mysql_select_db("$db_name")or die("cannot select DB");

// value sent from form 
$email_to=$_POST['email_to']; // table name 
$tbl_name=tz_members;

// retrieve password from table where e-mail is equal
 $sql="SELECT usr, pass, regIP FROM $tbl_name WHERE email='$email_to'"; $result=mysql_query($sql);

// if found this e-mail address, row must be 1 row // keep value in variable name "$count" 
$count=mysql_num_rows($result);

// compare if $count =1 row 
if($count==1) { $rows=mysql_fetch_array($result);

$your_username=$rows['usr']; $your_password=$rows['pass']; $your_ip=$rows['regIP']; $pass = substr(md5($your_ip.microtime().rand(1,100000)),0,6); // create a new pass
 mysql_query(" UPDATE tz_members SET pass='".md5($pass)."' WHERE email='".$email_to."'"); // update the db

// ---------------- SEND MAIL FORM ---------------- // send e-mail to ...
$to=$email_to;

// Your subject 
$subject="Your password here";

// From 
$header="from: your name ";

// Your message
 $messages= "Your password for login has been reset.\r\n"; $messages.="The new password is $pass \r\n"; $messages.="Regards \r\n";

// send email
 $sentmail = mail($to,$subject,$messages,$header);

mysql_free_result($result); }

// else if 
$count not equal 1 else if ($count==0) echo "Your email was not found in our database"; else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";

// if your email succesfully sent 
if($sentmail) { echo "The new password has been reset and sent to the email on record."; } else { echo "Cannot send the password to this e-mail address"; }

?>

这是一个从数据库重置密码的表单。

1 个答案:

答案 0 :(得分:2)

我认为发生的事情是你的评论中有回车。

更改

  // else if 
   $count not equal 1 else if ($count==0) echo "Your email was not found in our database";     
   else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";

   // else if $count not equal 1 

else if ($count==0) echo "Your email was not found in our database"; 
else echo "More than one (".$count.") email records was found in our database, please contact the administrator.";

修改

根据Halfer的评论,请参阅此处以获取有关一行if语句的讨论。 Formatting of if Statements