Jump to content

Recommended Posts

the problem is described within the code, please help

 

<?php

if ($_POST['submit']){

$username = $_POST['username'];
$companyname = $_POST['companyname'];
$secretquestion = $_POST['secretquestion'];
$secretanswer = $_POST['secretanswer'];

if ($username&&$companyname&&$secretquestion&&$secretanswer){

$connect = mysql_connect("***","***","***") or die ("Couldn't connect");
mysql_select_db("***") or die ("Couldn't find db");

$query = mysql_query("SELECT * FROM members WHERE username='$username'");

$numrows = mysql_num_rows($query);

if ($numrows !=0)
{
while ($row = mysql_fetch_assoc($query))
  {
$dbusername = $row['username'];
$dbcompanyname = $row['company'];
$dbsecretquestion = $row['secretquestion'];
$dbsecretanswer = $row['secretanswer'];
    $dbpersonalemail = $row['personalemail'];	
  }
  

  
  
  //check to see if they match
  if ($username==$dbusername&&$companyname==$dbcompanyname&&$secretquestion==$dbsecretquestion&&$secretanswer==$dbsecretanswer)
  {
  $random = rand(23456789,98765432);
  
   mysql_query("UPDATE members SET randomforgot='$random' WHERE username='$username'");
  
  echo "Success, we have sent you an email containing a random number, enter the random number below.<br><br>
  <form action='forgotpassword.php' method='POST'>
  <table width='100%'>
  <tr><td width='50%'></td><td></td></tr>
  <tr><td align='right'>Random number:</td><td><input type='text' name='randomnumber' maxlength='8' size='8'></td></tr>
  <tr><td></td><td align='left'><input type='submit' name='submitrandomnumber' value='Enter'></td></tr>
  </table>
  </form>
  ";

/*just below is where i am having my problem
when i click the submit button in the form just above it just
goes back to the very beginning of the script like the page has just been refreshed
even if there is information entered in the "<input type='text' name='randomnumber' maxlength='8' size='8'>" or not. but i want to redirect to /bob.php */
     
    
  if ($_POST['randomnumber']) 
  {
$randomnumber = $_POST['randomnumber'];
$dbrandomnumber = $row ['randomforgot'];

if ($randomnumber==$dbrandomnumber)
{
header("location:./bob.php");
}

  }

  //end of the problem
  

  }
  else
  $incorrectdetails = 
  "
<form action='forgotpassword.php' method='POST'>
<table>
<tr><td></td><td>Sorry we could not find those details<td></tr>
<tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr>
<tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr>
<tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr>
<tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr>
<tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr>
</table>
</form>
";
  


  
}
else
{
$incorrectuser = 
"
<form action='forgotpassword.php' method='POST'>
<table>
<tr><td></td><td>Username does not exist<td></tr>
<tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr>
<tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr>
<tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr>
<tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr>
<tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr>
</table>
</form>
";
}


}
else
{
$error = "
<form action='forgotpassword.php' method='POST'>
<table>
<tr><td></td><td>Please fill in all fields<td></tr>
<tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr>
<tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr>
<tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr>
<tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr>
<tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr>
</table>
</form>
";
}

}
?>

<?php echo $error ?>
<?php echo $incorrectuser ?>
<?php echo $incorrectdetails ?>

<?php
if (!$_POST['submit']){
echo "
<form action='forgotpassword.php' method='POST'>
<table>
<tr><td align='right'>Username:</td><td><input type='text' name='username' value='$username'></td></tr>
<tr><td align='right'>Company name:</td><td><input type='text' name='companyname' value='$companyname'></td></tr>
<tr><td align='right'>Secret Question:</td><td><select name='secretquestion'><option selected></option><option>Your pets name</option><option>Mothers maiden name</option><option>Favourite book</option><option>Favourite school teacher</option><option>Fathers first name</option></select></td></tr>
<tr><td align='right'>Answer:</td><td><input type='password' name='secretanswer'></td></tr>
<tr><td></td><td align='left'><input type='submit' name='submit' value='Send'></td></tr>
</table>
</form>
";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/172738-small-confusing-problem/
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.