Jump to content

Passing $_POST


adamlacombe

Recommended Posts

This is what I have for code:


<?php
$title="Login";
$metakeywords="login, email";
$metadescription="Login to Dating Snap!";

include('header.php');

  $user = clean_up($_POST['email']);
  $pass = clean_up($_POST['password']);

if($user && $pass)
{
$pass = md5($pass); //compare the encrypted password
$sql="SELECT id,email,type,password,activation_key FROM `users` WHERE `email`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) > 0)
    {
      $lllrow = mysql_fetch_assoc($query);
if($lllrow['activation_key'] == 0){
      $_SESSION['id'] = $lllrow['id'];
      $_SESSION['type'] = $lllrow['type'];
      $_SESSION['email'] = $lllrow['email'];
      $_SESSION['password'] = $lllrow['password'];

   $date=date("M d Y");
   $time=date("g:i A");
$sql3 ="UPDATE `users` SET `last_ip`='{$_SERVER['REMOTE_ADDR']}', `last_login`='$date $time' WHERE `id`='".$_SESSION['id']."'";
$res3 = mysql_query($sql3) or die(mysql_error());

}else{
echo "<div class='error'>You need to activate your account first!</div>";
}

echo '<meta http-equiv="REFRESH" content="0;url=index.php">';
    }
    else
   {
    echo "<div class='error'>Email and password combination is incorrect!</div>";
   }	
}else{			


if(!$_GET['step'] && $_POST['newpassword']){


$email = clean_up($_POST['email']);
$password = clean_up($_POST['newpassword']);


$sql = "SELECT * FROM `users` WHERE `email`='$email'";
$query = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($query) > 0) 
{
  echo "That email is already being used, please try another.";
}else{

$activation_number = rand( );

$subject = 'Activate your account on datingsnap.com';
$message = 'Dear '.$first.' '.$last.',<br>Thank you for registering for an account on Dating Snap. Please <a href="http://datingsnap.com/index.php?action=activate&id='.$activation_number.'">Click Here</a> to activate your new account.<br>All the best,<br> DatingSnap.com';
$headers = 'From: [email protected]' . "\r\n" .
    'Content-Type: text/html; charset=\"iso-8859-1\"' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();



  $sql = "INSERT into `users`(`activation_key`,`password`,`email`)
  VALUES ('$activation_number','".md5($password)."','$email');";

$query = mysql_query($sql) or die(mysql_error());

echo '<form method="post" action="index.php?action=login&step=1"><table width="100%">
<input id="email" type="hidden" name="email" value="$email">
<table width="100%">
<tr>
<td class="content">*<b>First Name:</b></td>
<td class="content"><input class="tarea" id="first" size="30" type="text" name="first"></td>
</tr>

<tr>
<td class="content">*<b>Last Name:</b></td>
<td class="content"><input class="tarea" id="last" size="30" type="text" name="last"></td>
</tr>

<tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit" value="Next step"></td></tr></form></table>';

}


if($_GET['step'] == "1" && $_POST['email']){

$email = clean_up($_POST['email']);
$first = clean_up($_POST['first']);
$last = clean_up($_POST['last']);

  $sql = "UPDATE `users` SET `first`='$first',`last`='$last' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());

echo '<table width="100%"><form method="post" action="index.php?action=login&step=2">
<input id="email" type="hidden" name="email" value="$email">
<tr>
<td class="content">*<b>Date of birth:</b><br><small>This will be used to calculate your age so be sure to use your correct birth date</small></td><td class="content">
<select name="month" id="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<select name="day" id="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<select name="year" id="year">';

$start_year = ($start_year) ? $start_year - 1 : date('Y') - 110;
    $end_year = ($end_year) ? $end_year : date('Y');
for ($i = $end_year; $i > $start_year; $i -= 1) {
        echo '<option value="'.$i.'">'.$i.'</option>';
    }

echo '</select>

</td>
</tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit" value="Next step"></td></tr></form></table>';

}




if($_GET['step'] == "2" && $_POST['email']){


$email = clean_up($_POST['email']);
	$month=clean_up($_POST['month']);
	$day=clean_up($_POST['day']);
	$year=clean_up($_POST['year']);

  $sql = "UPDATE `users` SET `bdate`='$year-$month-$day' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());


echo "Done step two!";
}


} //end if email

}




include('footer.php');
?>

 

How come $_POST['email'] isn't getting passed down the steps? I have a hidden field that holds it in each step... what am I overlooking?

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/
Share on other sites

<?php
$title="Login";
$metakeywords="login, email";
$metadescription="Login to Dating Snap!";

include('header.php'); 

$user = clean_up($_POST['email']); 
$pass = clean_up($_POST['password']);

if($user && $pass){$pass = md5($pass); 
//compare the encrypted password
$sql="SELECT id,email,type,password,activation_key FROM `users` WHERE `email`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

 

Would this be step 1? You should comment your code  :P

 

If it's failing on the first step, $user = clean_up($_POST['email']); isn't getting set.

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194033
Share on other sites

well if it is being inserted into the db and found there why isn't the hidden field sending $email down to the next form?

 

See:

  $sql = "INSERT into `users`(`activation_key`,`password`,`email`)
  VALUES ('$activation_number','".md5($password)."','$email');";

$query = mysql_query($sql) or die(mysql_error());

echo '<form method="post" action="index.php?action=login&step=1"><table width="100%">
<input id="email" type="hidden" name="email" value="$email">

 

the db is getting $email but I guess the hidden field isn't... I have no clue why

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194038
Share on other sites

Your submit button for step 2:

 

</tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit" value="Next step"></td></tr></form></table>'

 

Change To:

 

</tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit2" value="Next step"></td></tr></form></table>'

 

I think the issue is because you have to forms with the same name for each submit button, this gave me issues before.

 

I apoligize for running around, been a long day and I need coffee to wake back up.  :-[

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194048
Share on other sites

That's not me lol .. so you're still getting an issue with it not passing? I will test the sign up from my end if you'd like.

 

You set the $email to a session variable in step 1 and you should be able to use that in step 2 rather then assigning it to a variable again..

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194055
Share on other sites

Yeah I figured that out now because some how I am getting inserts from some where randomly. I have no query anywhere on the site that inserts into my feed table with the field named "type" with data called "videocomment" but they are being inserted :-/

 

....im kinda freaked out

 

 

anyways... im trying it with GET instead.. it should be able to run using POST though anyways like I said it works in that query why not just below it.. soo confused XD

 

 

EDIT:

I found that I didn't do: '.$email.'

I just has $email :P ugh little mistakes take longer to find lol but even now it isn't working XD

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194059
Share on other sites

Then if($_GET['step'] == "2")   isn't getting set. and causing the error.

 

That's because of how your working with your forms.

 

Give each form a unique submit name, change the $_GET['step'] == '2' to if (!isset($_POST['step2'])) && ...

 

Then you won't have to work with get, and you should be up and running. ALSO comment your code!

 

EDIT:

 

Don't forget to change action="index.php?action=login&step=1" to just action="index.php"

 

OR you could try "index.php?step=1" and so on.. because you don't use action=login

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194071
Share on other sites

I tried that and still it wont work... ugh!! Also it would need to be action=login because thats the file we are working in....

 

Now the first and last name will not go thru.. also, once I submit that form it goes to a empty page.

<?php
$title="Login";
$metakeywords="login, email";
$metadescription="Login to Dating Snap!";

include('header.php');

  $user = clean_up($_POST['email']);
  $pass = clean_up($_POST['password']);

if($user && $pass)
{
$pass = md5($pass); //compare the encrypted password
$sql="SELECT id,email,type,password,activation_key FROM `users` WHERE `email`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) > 0)
    {
      $lllrow = mysql_fetch_assoc($query);
if($lllrow['activation_key'] == 0){
      $_SESSION['id'] = $lllrow['id'];
      $_SESSION['type'] = $lllrow['type'];
      $_SESSION['email'] = $lllrow['email'];
      $_SESSION['password'] = $lllrow['password'];

   $date=date("M d Y");
   $time=date("g:i A");
$sql3 ="UPDATE `users` SET `last_ip`='{$_SERVER['REMOTE_ADDR']}', `last_login`='$date $time' WHERE `id`='".$_SESSION['id']."'";
$res3 = mysql_query($sql3) or die(mysql_error());

}else{
echo "<div class='error'>You need to activate your account first!</div>";
}

echo '<meta http-equiv="REFRESH" content="0;url=index.php">';
    }
    else
   {
    echo "<div class='error'>Email and password combination is incorrect!</div>";
   }	
}else{			


if(!$_GET['step'] && $_POST['newpassword']){


$email = clean_up($_POST['email']);
$password = clean_up($_POST['newpassword']);


$sql = "SELECT * FROM `users` WHERE `email`='$email'";
$query = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($query) > 0) 
{
  echo "That email is already being used, please try another.";
}else{

$activation_number = rand( );

$subject = 'Activate your account on datingsnap.com';
$message = 'Dear '.$first.' '.$last.',<br>Thank you for registering for an account on Dating Snap. Please <a href="http://datingsnap.com/index.php?action=activate&id='.$activation_number.'">Click Here</a> to activate your new account.<br>All the best,<br> DatingSnap.com';
$headers = 'From: [email protected]' . "\r\n" .
    'Content-Type: text/html; charset=\"iso-8859-1\"' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();



  $sql = "INSERT into `users`(`activation_key`,`password`,`email`)
  VALUES ('$activation_number','".md5($password)."','$email');";

$query = mysql_query($sql) or die(mysql_error());

echo '<form method="post" action="index.php?action=login"><table width="100%">
<input id="email" type="hidden" name="email" value="'.$email.'">
<table width="100%">
<tr>
<td class="content">*<b>First Name:</b></td>
<td class="content"><input class="tarea" id="first" size="30" type="text" name="first"></td>
</tr>

<tr>
<td class="content">*<b>Last Name:</b></td>
<td class="content"><input class="tarea" id="last" size="30" type="text" name="last"></td>
</tr>

<tr><td width="150" class="content"></td><td class="content"><input type="submit" name="step1" value="Next step"></td></tr></form></table>';

}


if ($_POST['step1'] && $_POST['email']){

$email = clean_up($_POST['email']);
$first = clean_up($_POST['first']);
$last = clean_up($_POST['last']);

  $sql = "UPDATE `users` SET `first`='$first',`last`='$last' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());

echo '<table width="100%"><form method="post" action="index.php?action=login">
<input id="email" type="hidden" name="email" value="'.$email.'">
<tr>
<td class="content">*<b>Date of birth:</b><br><small>This will be used to calculate your age so be sure to use your correct birth date</small></td><td class="content">
<select name="month" id="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<select name="day" id="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<select name="year" id="year">';

$start_year = ($start_year) ? $start_year - 1 : date('Y') - 110;
    $end_year = ($end_year) ? $end_year : date('Y');
for ($i = $end_year; $i > $start_year; $i -= 1) {
        echo '<option value="'.$i.'">'.$i.'</option>';
    }

echo '</select>

</td>
</tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="step2" value="Next step"></td></tr></form></table>';

}



if ($_POST['step2'] && $_POST['email']){


$email = clean_up($_POST['email']);
	$month=clean_up($_POST['month']);
	$day=clean_up($_POST['day']);
	$year=clean_up($_POST['year']);

  $sql = "UPDATE `users` SET `bdate`='$year-$month-$day' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());


echo "Done step two!";
}


} //end if email

}




include('footer.php');
?>

 

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194078
Share on other sites

I didn't change the action="" line but it may not matter for the changes I've made.

 

I can't say this will work but give it a try. I attached the updated code to this post to make it easier to copy & paste or just upload.

 

<?php
$title="Login";
$metakeywords="login, email";
$metadescription="Login to Dating Snap!";

include('header.php');

  $user = clean_up($_POST['email']);
  $pass = clean_up($_POST['password']);

if($user && $pass)
{
$pass = md5($pass); //compare the encrypted password
$sql="SELECT id,email,type,password,activation_key FROM `users` WHERE `email`='$user' AND `password`='$pass'";
$query=mysql_query($sql) or die(mysql_error());

    if(mysql_num_rows($query) > 0)
    {
      $lllrow = mysql_fetch_assoc($query);
if($lllrow['activation_key'] == 0){
      $_SESSION['id'] = $lllrow['id'];
      $_SESSION['type'] = $lllrow['type'];
      $_SESSION['email'] = $lllrow['email'];
      $_SESSION['password'] = $lllrow['password'];

   $date=date("M d Y");
   $time=date("g:i A");
$sql3 ="UPDATE `users` SET `last_ip`='{$_SERVER['REMOTE_ADDR']}', `last_login`='$date $time' WHERE `id`='".$_SESSION['id']."'";
$res3 = mysql_query($sql3) or die(mysql_error());

}else{
echo "<div class='error'>You need to activate your account first!</div>";
}

echo '<meta http-equiv="REFRESH" content="0;url=index.php">';
    }
    else
   {
    echo "<div class='error'>Email and password combination is incorrect!</div>";
   }	
}else{			

// I have no clue where your getting step from for updating the user password because you only have 2 forms below
// and they are followed below with code to support them

if(!$_GET['step'] && $_POST['newpassword']){


$email = clean_up($_POST['email']);
$password = clean_up($_POST['newpassword']);


$sql = "SELECT * FROM `users` WHERE `email`='$email'";
$query = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($query) > 0) 
{
  echo "That email is already being used, please try another.";
}else{

$activation_number = rand( );

$subject = 'Activate your account on datingsnap.com';
$message = 'Dear '.$first.' '.$last.',<br>Thank you for registering for an account on Dating Snap. Please <a href="http://datingsnap.com/index.php?action=activate&id='.$activation_number.'">Click Here</a> to activate your new account.<br>All the best,<br> DatingSnap.com';
$headers = 'From: [email protected]' . "\r\n" .
    'Content-Type: text/html; charset=\"iso-8859-1\"' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();



  $sql = "INSERT into `users`(`activation_key`,`password`,`email`)
  VALUES ('$activation_number','".md5($password)."','$email');";

$query = mysql_query($sql) or die(mysql_error());

// Form for updating the firstname, lastname, and email address

echo '<form method="post" action="index.php?action=login&step=1"><table width="100%">
<input id="email" type="hidden" name="email" value="$email">
<table width="100%">
<tr>
<td class="content">*<b>First Name:</b></td>
<td class="content"><input class="tarea" id="first" size="30" type="text" name="first"></td>
</tr>

<tr>
<td class="content">*<b>Last Name:</b></td>
<td class="content"><input class="tarea" id="last" size="30" type="text" name="last"></td>
</tr>

<tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit1" value="Next step"></td></tr></form></table>';

}

// If the form name submit1 is submitted then we can update the firstname, lastname, and email address

if(isset($_GET['submit1'])) && (isset($_POST['email'])){

$email = clean_up($_POST['email']);
$first = clean_up($_POST['first']);
$last = clean_up($_POST['last']);

  $sql = "UPDATE `users` SET `first`='$first',`last`='$last' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());

// Form for submitting the user's birthday

echo '<table width="100%"><form method="post" action="index.php?action=login&step=2">
<input id="email" type="hidden" name="email" value="$email">
<tr>
<td class="content">*<b>Date of birth:</b><br><small>This will be used to calculate your age so be sure to use your correct birth date</small></td><td class="content">
<select name="month" id="month">
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>

<select name="day" id="day">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
<option value="7">7</option>
<option value="8">8</option>
<option value="9">9</option>
<option value="10">10</option>
<option value="11">11</option>
<option value="12">12</option>
<option value="13">13</option>
<option value="14">14</option>
<option value="15">15</option>
<option value="16">16</option>
<option value="17">17</option>
<option value="18">18</option>
<option value="19">19</option>
<option value="20">20</option>
<option value="21">21</option>
<option value="22">22</option>
<option value="23">23</option>
<option value="24">24</option>
<option value="25">25</option>
<option value="26">26</option>
<option value="27">27</option>
<option value="28">28</option>
<option value="29">29</option>
<option value="30">30</option>
<option value="31">31</option>
</select>

<select name="year" id="year">';

$start_year = ($start_year) ? $start_year - 1 : date('Y') - 110;
    $end_year = ($end_year) ? $end_year : date('Y');
for ($i = $end_year; $i > $start_year; $i -= 1) {
        echo '<option value="'.$i.'">'.$i.'</option>';
    }

echo '</select>

</td>
</tr><tr><td width="150" class="content"></td><td class="content"><input type="submit" name="submit2" value="Next step"></td></tr></form></table>';

}


// If the form submit2 is submitted we can update the user's birthday and email address

if(isset($_POST['submit2'])) && (isset($_SESSION['email'])) {

// it's a bit redundant because your already establishing and cleaning up the email at the start of the script
$email = clean_up($_SESSION'email']);
	$month=clean_up($_POST['month']);
	$day=clean_up($_POST['day']);
	$year=clean_up($_POST['year']);

  $sql = "UPDATE `users` SET `bdate`='$year-$month-$day' WHERE `email`='$email'";

$query = mysql_query($sql) or die(mysql_error());


echo "Done step two!";
}


} //end if email

}




include('footer.php');

 

[attachment deleted by admin]

Link to comment
https://forums.phpfreaks.com/topic/232125-passing-_post/#findComment-1194092
Share on other sites

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.