Usint PHP, I'm trying to add the username, used in a login form, to the MYSQL table of another form.

Scenario: User "x" logs in (providing his username, "x", and a password). The username and password are stored in a MYSQL table called "users". Once "x" is logged in, he is directed to another form, where he provides his real name and other information and submits that form, and that information is stored in MYSQL table "register".

I want to be able to store "x" in a field of "register", without having "x" supplied in the form.

I think I'm close and have written the following code (but it's not working yet):

$tbl_name="users"; // Table name 

// Define $myusername and $mypassword 

// 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 username FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";

    //build and submit query
    $query = <<<HERE
null, '$first_name', '$last_name', '$address', '$city', '$state', '$zip_code', 
'$home_phone', '$cell_phone', '2011-01-01', '2011-01-02', '$str', null, null, null, null, 1);


Can someone please help?

6 Years
Discussion Span
Last Post by Threza

wait... let me say this to you...you want the php get the previous variables of the previous form right???

well if that is you can get the previous variables value.... this is called "variable passing by reference" for example your previous form has a variable $username... and the current form has $username again or $username_2 let's use $username for the current form's variable.

There are 2 techinques of variable passing by reference. according to your problem the technique used here is in a flow "Passing the Message to all the files of the entire site" this is the first technique.

you can do this way:

<form action="form2.php" method="POST">
Username:<input type=text name="username">
<!---note: the "name" in the tag will be pass the value by reference because of the action and method attribute


echo"<form action=\"form3.php\" method=\"post\">";
$username=$_POST['username']; //<---this "['username']" gets the value from the html form.

let's say you finished business w/ form2.php and you want to pass your $username value in your form2.php to your form3.php

$USERNAME=$_POST['uername']; //<--- this time, the "['username']" here is not the username in html... rather it was the username in the $username of your form2.php

bare this in mind what ever is the variable that you want to copy from your previous form is case sensitive and spelling sensitive but please remove the $ sign when you want to call the value of the previous form's variable, OK.
and another to be remeinded is if you post at the first place then use the post in your entire site when doing this will ya??

Edited by masterjiraya: n/a


u can also set the username in session..


And get from session like,

$strUserName= $_SESSION;

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.