Sending variables through post via a script page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
getseen
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 8:50 pm

Sending variables through post via a script page

Post by getseen »

Hi there,

I am making a website at the moment, and it has a create user account page. So, when the user creates an account, they input a name, email and password into the form. Once they have pressed submit, this is then sent to my database, along with a unique user ID. This is basically the last number entered into the database plus 1.

However on the same php page, they are presented with a login page. If they enter their details correctly, they can go to stage 3. Now I would easily be able to take the variable via POST to stage 3 if the login varification was on the same page as stage 3, however if goes via a seperate php file. IE.

This bit creates the client ID

Code: Select all

<?php
$data = mysql_query("SELECT * FROM sellers ORDER BY clientid DESC")
or die(mysql_error());
$info = mysql_fetch_array( $data );
$ClientID = $info[clientid] + 1;
?>
 
<?php
    if ($_SERVER['REQUEST_METHOD'] == "POST") 
    {
        # escape data and set variables
        
        
        
$EmailAddress = addslashes($_POST["emailaddy"]);
$FirstName = addslashes($_POST["name"]);
$Password = addslashes($_POST["password"]);         
 
$sql  = " INSERT INTO sellers";
$sql .= " ( clientid, email, name, password) VALUES ";
$sql .= " ('$ClientID','$EmailAddress', '$FirstName', '$Password') ";
 
$result = mysql_query($sql, $cid);
 
       
if (mysql_error()) { print "Database ERROR: " . mysql_error(); }
 
[COLOR="Red"]This bit comes up once they have submitted the form below, its the login form. This form leads to checklogin2.php which then leads to stage3[/COLOR]
 
 
print $ClientID. "
<strong>Thank you very much for signing up to our service.</strong><br><br> We have sent you a confirmation email. Use your email address and your password to log-in below to your user area. <br>
<form name='form1' method='post' action='checklogin2.php'>
<h2>Email Address:</h2>
<input type='hidden' name='clientid1' value='<?php  echo $ClientID; ?>'><br>
<input name='myusername' type='text' id='myusername'><br>
<h2>Password:</h2>
<input name='mypassword' type='password' id='mypassword'><br><br>
<input type='submit' name='Submit' value='Login'></p>
</form>
</tr>
</p><br /><br /></div><div style='clear: both;'></div><div id='footer'></div></div><div style='clear: both;'></div></div></body></html>";
 
 
exit;
}
?><strong>Thank you for choosing to create an account with us.</strong><br>
 
Please fill in the form below<br>
<form method="post" action="seller_registration.php">
<table>
<tr>
<td class="userloginbuyerl">Name:</td>
<td><input name="name" value="Your Name"></td>
</tr>
<tr>
<td class="userloginbuyerl">Email Address:</td>
<td><input name="emailaddy" value="Email Address">
</td>
</tr>
<tr>
<td class="userloginbuyerl">Password:</td>
<td>
<input name="password" value="Password">
</td>
</tr>
<tr>
<td>
</td>
<td><input type="submit">
</td>
</tr>
</table>
</form>
This is checklogin2.php

Code: Select all

<?php
$host="localhost"; // Host name
$username="********"; // Mysql username
$password="********"; // Mysql password
$db_name="********"; // Database name
$tbl_name="********"; // Table name
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
 
// username and password sent from form
$myusername=$_POST['myusername'];
$mypassword=$_POST['mypassword'];
$myclientid=$_POST['clientid1'];
 
// To protect MySQL injection (more detail about MySQL injection)
$myusername = stripslashes($myusername);
$mypassword = stripslashes($mypassword);
$myusername = mysql_real_escape_string($myusername);
$mypassword = mysql_real_escape_string($mypassword);
 
$sql="SELECT * FROM $tbl_name WHERE email='$myusername' and password='$mypassword'";
$result=mysql_query($sql);
 
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
 
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword");
session_register("clientid1");
header("location:loginsuccess2.php");
}
else {
echo "Wrong Username or Password";
}
?>
As you can see, ive sent clientid from the first form, to checklogin2.php. Now I need to know how to send it to the next page, or receive it from the next page.

Any help please :)
User avatar
susrisha
Forum Contributor
Posts: 439
Joined: Thu Aug 07, 2008 11:43 pm
Location: Hyderabad India

Re: Sending variables through post via a script page

Post by susrisha »

Try to look for sessions concept

Code: Select all

 
$_SESSION
 
getseen
Forum Newbie
Posts: 14
Joined: Thu Jul 23, 2009 8:50 pm

Re: Sending variables through post via a script page

Post by getseen »

Excellent, it was just what Im after.

Thank you very much.
Post Reply