0

I am really stuck on this problem. How can I make it work? It selects from email the user and resends on email the password.

I got an error on line 45 but cannot find it:

Parse error: syntax error, unexpected 'not' (T_STRING) in /home/xxxxxx/public_html/xxxx/email.php on line 45

Here is my code:

    <?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"; }

?>

It's a form that reset password from database.

halfer
  • 18,701
  • 13
  • 79
  • 158
  • 3
    **Danger**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) and should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). You are also **vulnerable to [SQL injection attacks](http://bobby-tables.com/)** that a modern API would make it easier to [defend](http://stackoverflow.com/questions/60174/best-way-to-prevent-sql-injection-in-php) yourself from. – Quentin Apr 06 '14 at 09:13
  • "al time i got an error on line 45 but cannot find it" — What error? – Quentin Apr 06 '14 at 09:13
  • 2
    You are using [an unsuitable hashing algorithm](http://php.net/manual/en/faq.passwords.php) and need to [take better care](https://www.owasp.org/index.php/Password_Storage_Cheat_Sheet) of your users' passwords. – Quentin Apr 06 '14 at 09:14
  • Parse error: syntax error, unexpected 'not' (T_STRING) in /home/xxxxxx/public_html/xxxx/email.php on line 45 – user3501432 Apr 06 '14 at 09:15
  • 3
    `$count not equal 1` on line 45 is an invalid expression (as far as I know). You probably meant `if ($count != 1)`. – DanielGibbs Apr 06 '14 at 09:17
  • 2
    Hi there. When asking questions, please add in all necessary information. If you get an error, it is best to state the error in the question, rather than wait for someone to ask you what it is. – halfer Apr 06 '14 at 09:21
  • Now it getting that error, seem the code it is broken or something? Parse error: syntax error, unexpected 'else' (T_ELSE) in /home/xxxx/public_html/xxx/email.php on line 45 – user3501432 Apr 06 '14 at 09:26
  • Right, because you don't have a body for your `if` condition (oops, I missed that before). See andrew's answer below for what you are probably trying to do. – DanielGibbs Apr 06 '14 at 09:27

1 Answers1

2

I think what happened is you have a carriage return in your comment.

Change

  // 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.";

to

   // 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.";

Edit

As per Halfer's comment, see here for a discussion on one line if statements. Formatting of if Statements

Community
  • 1
  • 1
andrew
  • 8,614
  • 7
  • 25
  • 56
  • It might be a good idea to recommend always using braces - using them only some of the time can be a tripwire for beginners, since it may not be clear what is included in an if/else clause and what is not. – halfer Apr 06 '14 at 09:34