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
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

Link to comment
Share on other sites

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
.
.
.
}

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.