Jump to content

[SOLVED] if elseif syntax problem


SkyRanger

Recommended Posts

I am having a syntax problem and not sure what the problem is.  Can somebody please have a look and let me know what the problem is:

 

if(isset($_POST['Recover']))

{
if($username == $_POST['username']){

	  mysql_connect("localhost", "username", "pass") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

$result = mysql_query("SELECT * FROM admin where username = '$username'") 
or die(mysql_error());  

while($row = mysql_fetch_array( $result )) {
echo $row['email']; //just a test to ensure database connects
} elseif($username == '') {
echo "That username is not found in our database";
}
	  } else { 
	  
?>
<form

 

The Error I am getting is:

 

Parse error: syntax error, unexpected T_ELSEIF in /home/esscal/public_html/admin/recover.php on line 28

Line 28 is: } elseif($username == '') {

Link to comment
https://forums.phpfreaks.com/topic/153213-solved-if-elseif-syntax-problem/
Share on other sites

Yeah, I fixed allot of that mess, but I found a new problem which I cannot figure out how to fix.  I am still a noob with php scratching my way through code with allot of research and trial and error.

 

I can get it to work with a proper username that is stored in the DB but not when I put none or the wrong one, It keeps coming up with the error:

 

Notice: Undefined variable: adminuser in /home/esscal/public_html/admin/recover.php on line 29

Line 29 is: if($username == $adminuser){

 

Below is the full code:

 

if(isset($_POST['Recover']))
{
$username = $_POST['username'];

mysql_connect("localhost", "uname", "pwrd") or die(mysql_error());
mysql_select_db("dbase") or die(mysql_error());

$result = mysql_query("SELECT * FROM admin where username = '$username'")
or die(mysql_error()); 

while($row = mysql_fetch_array( $result )) {
$adminuser = $row['username']; //just a test to ensure database connects
}

   if($username == $adminuser){
  
  echo "Username Correct";

} 
elseif($username == '') 
{
   echo "That username is not found in our database";
}
   } else {
       
?>
<form

Well if your query doesn't match a username then the variables adminuser will never be assinged to anything because $row['username'] never exists.

 

You should do a check to see if any rows are returned:

 

if(mysql_num_rows($result) == 0) {
   echo "Error no matches for that username";
} else {
   $adminuser = $row['username'];
   // Proceed with rest of code
.
.
.
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.