Jump to content

[SOLVED] else problam (rewritten code)


redarrow

Recommended Posts

Hi there i have rewritten this code in all php's

statements and function's as possable even using a catch to

catch true or false the else dosent work any idears please cheers.

 

I have tried .....

 

matching the varables no luck

matching with mysql_num_rows no luck

matching a condition via varables no luck

used the form with hidden varable no luck

used sessions no luck

 

my elese wont work why!!!!!!!!!

 

<?php


//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//`privert_word` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//



$db=mysql_connect("xxx","xxx","xxx");
$db_result=mysql_select_db("database_test",$db);


if($_POST['submit']){

$true=$_POST['true'];

$new_pass=rand(0,123456);

$pass=$new_pass;

$new_pass=(md5($_POST['new_pass']));

$privert_word=$_POST['privert_word'];

$username=$_POST['username'];

$email=$_POST['email'];


if( empty($username) || empty($email) ){

echo"<center> <font color='red'>Please fill in all the form!</font></center>";

}


$sql="SELECT * from pass where username='$username' AND email='$email'  and privert_word='$privert_word' and id='00001'";
$sql_result=mysql_query($sql)or die(mysql_error());


while($x=mysql_fetch_assoc($sql_result)){

    if(($x['username'] || $x['email'])==1){

$true="TRUE";
    
    }else{
    	
    $true="FALSE";
    
    }
    	
if($true=="TRUE"){
    	
    
$new_pass=mysql_real_escape_string($new_pass);


$sql2="UPDATE pass set password='$new_pass' WHERE 
username='$username' AND email='$email' and privert_word='$privert_word' and id='00001'";
$result2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>
		    	Your new ".$x['username']." password 
		    	<br><br><br><br>Username: ".$x['username']."
		    	<br><br>Password: $pass
		    	<br><br>Please try to remember your new password cheers!
		    	<br><br>or change your password in your members area
		    	 to a easy remembered password";
		    	
		    
}elseif($true=="FALSE"){

		    	
               echo "Sorry we have no record of your username: $username or email: $email
	       <br><br>please join our website <br><br>
	       <a href='join.php'>join now!<a>";
}
}
  }	

?>

<center>
<form method="POST" action="password_recovery.php">
<h1>Password recovery</h1>
<br>
Please provide username:
<br><br>
<input type="text" name="username">
<br><br>
Please provide email address:
<br><br>
<input type="text" name="email">
<br><br>
Please tell us your privert saying:
<br><br>
<input type="text" name="privert_word">
<br><br>
<input name="submit" type="submit" value="Send">
</form>
</center>

Link to comment
Share on other sites

here another way still no luck....

 

<?php


//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//`privert_word` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//



$db=mysql_connect("xxx","xxx","xxx");
$db_result=mysql_select_db("database_test",$db);


if(isset($_POST['submit'])){


$new_pass=rand(0,123456);

$pass=$new_pass;

$new_pass=(md5($_POST['new_pass']));

$privert_word=$_POST['privert_word'];

$username=$_POST['username'];

$email=$_POST['email'];

$id=$_POST['id'];


$sql="SELECT * from pass where username='$username' AND email='$email'  and privert_word='$privert_word' and id='00001'";
$sql_result=mysql_query($sql)or die(mysql_error());


while($x=mysql_fetch_assoc($sql_result)){


 if( (mysql_num_rows($sql_result)==1)){
    
   
 $new_pass=mysql_real_escape_string($new_pass);


$sql2="UPDATE pass set password='$new_pass' WHERE 
username='$username' AND email='$email' and privert_word='$privert_word' and id='00001'";
$result2=mysql_query($sql2) or die(mysql_error());


		    	echo "<br><br>
		    	Your new ".$x['username']." password 
		    	<br><br><br><br>Username: ".$x['username']."
		    	<br><br>Password: $pass
		    	<br><br>Please try to remember your new password cheers!
		    	<br><br>or change your password in your members area
		    	 to a easy remembered password";
		    	
		    
		    	exit;
 }else{


		    	echo "Sorry we have no record of your username: $username or email: $email
	       <br><br>please join our website <br><br>
	       <a href='join.php'>join now!<a>";            
               
		    	
		    	exit;
}
}
  }

?>

<center>

<form method="POST" action="password_recovery.php">

<h1>Password recovery</h1>

<br>

Please provide username:
<br><br>

<input type="text" name="username">

<br><br>

Please provide email address:

<br><br>

<input type="text" name="email">

<br><br>

Please tell us your privert saying:

<br><br>

<input type="text" name="privert_word">
<br><br>

<input name="submit" type="submit" value="Send">

</form>

</center>

Link to comment
Share on other sites

tried it this way aswell still no elese working

<?php


//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//`privert_word` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//



$db=mysql_connect("xxx","xxx","xxx");
$db_result=mysql_select_db("database_test",$db);


if(isset($_POST['submit'])){


$new_pass=rand(0,123456);

$pass=$new_pass;

$new_pass=(md5($_POST['new_pass']));


$sql="SELECT * from `pass` where `username`='".$_POST['username']."' AND `email`='".$_POST['email']."' AND `privert_word`='".$_POST['privert_word']."' AND `id`='00001'";
$sql_result=mysql_query($sql)or die(mysql_error());


while($x=mysql_fetch_assoc($sql_result)){


 if( (mysql_num_rows($sql_result)==1)){
    
   
 $new_pass=mysql_real_escape_string($new_pass);


$sql2="UPDATE `pass` set `password`='".$_POST['new_pass']."' WHERE 
`username`='".$_POST['username']."' AND `email`='".$_POST['email']."' AND `privert_word`='".$_POST['privert_word']."' AND `id`='00001'";
$result2=mysql_query($sql2) or die(mysql_error());



		    	   	echo "<br><br>
		    	Your new ".$x['username']." password 
		    	<br><br><br><br>Username: ".$x['username']."
		    	<br><br>Password: $pass
		    	<br><br>Please try to remember your new password cheers!
		    	<br><br>or change your password in your members area
		    	 to a easy remembered password";
		    
		    	exit;
 }else{


		    	echo "Sorry we have no record of your username: $username or email: $email
	       <br><br>please join our website <br><br>
	       <a href='join.php'>join now!<a>";            
               
		    	
		    	exit;
}
}
  }

?>

<center>

<form method="POST" action="password_recovery.php">

<h1>Password recovery</h1>

<br>

Please provide username:
<br><br>

<input type="text" name="username">

<br><br>

Please provide email address:

<br><br>

<input type="text" name="email">

<br><br>

Please tell us your privert saying:

<br><br>

<input type="text" name="privert_word">
<br><br>

<input name="submit" type="submit" value="Send">

</form>

</center>

Link to comment
Share on other sites

posting as one page cheers.....(no elese working mate)

<center>

<form method="POST" action="password_recovery.php">

<h1>Password recovery</h1>

<br>

Please provide username:
<br><br>

<input type="text" name="username">

<br><br>

Please provide email address:

<br><br>

<input type="text" name="email">

<br><br>

Please tell us your privert saying:

<br><br>

<input type="text" name="privert_word">
<br><br>

<input name="submit" type="submit" value="Send">

</form>

</center>

Link to comment
Share on other sites

You have the check for the number of records returned and the fetch of the record reverse. The check for the number should come first. Also, since you're only expecting one record to be returned, you don't need the while statement.  Try:

<?php
//
//CREATE TABLE `database_test`.`pass` (
//`id` SMALLINT( 5 ) UNSIGNED ZEROFILL NOT NULL AUTO_INCREMENT PRIMARY KEY ,
//`username` VARCHAR( 25 ) NOT NULL ,
//`password` VARCHAR( 35 ) NOT NULL ,
//`email` VARCHAR( 50 ) NOT NULL
//`privert_word` VARCHAR( 50 ) NOT NULL
//) ENGINE = InnoDB 
//
$db=mysql_connect("xxx","xxx","xxx");
$db_result=mysql_select_db("database_test",$db);
if(isset($_POST['submit'])){
$new_pass=rand(0,123456);	
$pass=$new_pass;
$new_pass=(md5($_POST['new_pass']));
$sql="SELECT * from `pass` where `username`='".$_POST['username']."' AND `email`='".$_POST['email']."' AND `privert_word`='".$_POST['privert_word']."' AND `id`='00001'";
$sql_result=mysql_query($sql)or die(mysql_error());
if( (mysql_num_rows($sql_result)==1)){
	$x=mysql_fetch_assoc($sql_result))
	$new_pass=mysql_real_escape_string($new_pass);
	$sql2="UPDATE `pass` set `password`='".$_POST['new_pass']."' WHERE 
	`username`='".$_POST['username']."' AND `email`='".$_POST['email']."' AND `privert_word`='".$_POST['privert_word']."' AND `id`='00001'";
	$result2=mysql_query($sql2) or die(mysql_error());
	echo "<br><br>
		Your new ".$x['username']." password 
		<br><br><br><br>Username: ".$x['username']."
		<br><br>Password: $pass
		<br><br>Please try to remember your new password cheers!
		<br><br>or change your password in your members area
		to a easy remembered password";
	exit;
}else{
	echo "Sorry we have no record of your username: $username or email: $email
		<br><br>please join our website <br><br>
		<a href='join.php'>join now!<a>";            
	exit;
}
}
?>

 

BTW, I fixed your indentation and removed the extraneous blank lines.

 

Ken

Link to comment
Share on other sites

and this i take it was the wrong way around

 

while($x=mysql_fetch_assoc($sql_result)){

 

 

if( (mysql_num_rows($sql_result)==1)){

 

should be

 

 

if( (mysql_num_rows($sql_result)==1)){

 

while($x=mysql_fetch_assoc($sql_result)){

 

 

mysql_num_rows should off b first then a while

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.