Hello All,
I want to know that is it possible to store multiple form values into a single record of a table.
form1 (in login.html):
<form name="accountinput" method="post" action="st-log1.php">
Account type:
<input type="radio" name="account" value="1">Student
<input type="radio" name="account" value="2">Faculty</td>
Enter Valid e-mail:
<input type="text" name="email">
<input type="submit" value="submit"></td>
</form>
form2(in st-log1.php):
<form name="user_info" action="variables.php" method="post">
Admission number: <input type="text" name="admission">
Username: <input type="text" name="user">
Password: <input type="password" name="password">
Re-enter password:<input type="password" name="password">
Gender: <input type="radio" name="gender" value="M">Male
<input type="radio" name="gender" value="F">Female
<input type="submit" value="submit">
</form>
php code in (variable.php):
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die('could not connect:'. mysql_error());
}
mysql_select_db("cis",$con);
$sql = "INSERT INTO user(type_id, email_id, admission_no, user_name, password, gender) VALUES ('$_POST[account]','$_POST[email]','$_POST[admission]','$_POST[user]','$_POST[password]','$_POST[gender]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
here m first trying to read all the values from first form. Then moving to st-log1.php page and after reading all the values in form 2 in that page i want submit both the form values as a single record of user table in database...pls anyone guide me wheather it is possible or not..any help would be greatly appreciated.
storing multiple html form values into single database recor
Moderator: General Moderators
-
pnsrinivasreddy
- Forum Newbie
- Posts: 2
- Joined: Sat Feb 07, 2009 2:54 am
Re: storing multiple html form values into single database recor
i have a question.. why do you want two forms??
you can put both the forms into a single one and get the values right??
If you are particular about doing it in two forms, session variables is your solution. First let me know if you really need two forms and then i shall give you some sample code to work with the sessions and the solution.
Please put the code in code tags provided by the forum. Makes it easy for others to read your code.
See other posts for reference.
you can put both the forms into a single one and get the values right??
If you are particular about doing it in two forms, session variables is your solution. First let me know if you really need two forms and then i shall give you some sample code to work with the sessions and the solution.
Please put the code in code tags provided by the forum. Makes it easy for others to read your code.
See other posts for reference.
-
pnsrinivasreddy
- Forum Newbie
- Posts: 2
- Joined: Sat Feb 07, 2009 2:54 am
Re: storing multiple html form values into single database recor
Hi,
It is obvious to me to use those two forms. Now i will look further about session variables. If u provide me the code then it would be a great help to me.
Thank u,
srinu
It is obvious to me to use those two forms. Now i will look further about session variables. If u provide me the code then it would be a great help to me.
Thank u,
srinu
Re: storing multiple html form values into single database recor
okay if thats the case.. i shall try to give you some basics and code.. will take an hour ;P
Re: storing multiple html form values into single database recor
st-log1-page.. the following code to be added at the start
in the variables.php page : this code at the start
Code: Select all
<?php
if(!isset($_SESSION))
{
session_start();
}//this if condition should be at the start of your page..
//there should be no code before this
//assign the posted values into the session in this page..
$_SESSION['account']= $_POST['account'];
$_SESSION['email'] = $_POST['email'];
//you have now assigned the values that are got from the
//post of the form1.
//now paste the rest of the form2 and other data of the page from here.
?>
Code: Select all
if(!isset($_SESSION))
{
session_start();
}//this if condition should be at the start of your page..
//there should be no code before this
//retrieve the variables from the session
$account = $_SESSION['account'];
$email = $_SESSION['email'];
//rest of the code goes as it is..
//you have to replace $_POST['account'] with $account and
//$_POST['email'] with $email in the mysql query