Save form data after submitting to a page within website
Posted: Tue Feb 28, 2012 9:11 am
Hi!
I am trying to make a "My profile" section for members, where they can fill in data about themselves( name, country, city etc). So i made a "edit_profile.html" form, which is submitted to "my_profile.php". This is the my_profile.php script:
<html>
<body>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);
$sql="INSERT INTO PROFILE (FirstName, LastName, Dateofbirth, Gender, Country, City, AboutMe, Email)
VALUES
('$_GET[fname]','$_GET[lname]','$_GET[day], $_GET[month], $_GET[year]','$GET_[gender]','$_GET[country]','$_GET[city]','$_GET[aboutme]','$_GET[email]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
<?php
$name = $_GET['fname'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">First name: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['lname'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Last name: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['day'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Date </span>';
$name = $_GET['month'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">of </span>';
$name = $_GET['year'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">birth: </span>';
$name = $_GET['day'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
$name = $_GET['month'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
$name = $_GET['year'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['gender'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Gender: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['country'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Country: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['city'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">City: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['aboutme'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">About me: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['email'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">E-mail: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
</body>
</html>
Now...the data from the "edit_profile.html (Edit Profile section)" is submitted into "my_profile.php" (My profile section) page and also into mysql db, but if i leave the "My profile" section and come back, the input data is gone from the page, remaining only in mysql db and every time i click "My profile" it creates a blank (unfilled with data) row in the mysql database. The important thing is, i need the data to be saved in "My profile" section after submitting the form and stay there all the time so the member/members can see it whenever he/they wants/want.
I searched the internet but found only "submit form to database" and "save form to a text file". I want my site to have a My profile like social sites: facebook, hi5, date sites, not so complex, a simple one, but to make an idea of what i need.
If someone can help with some scripts, ideas, guides, links, i'll really appreciate it. Every bit counts!
Looking forward to your replies. Thanks!
I am trying to make a "My profile" section for members, where they can fill in data about themselves( name, country, city etc). So i made a "edit_profile.html" form, which is submitted to "my_profile.php". This is the my_profile.php script:
<html>
<body>
<?php
$con = mysql_connect("localhost","username","password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("databasename", $con);
$sql="INSERT INTO PROFILE (FirstName, LastName, Dateofbirth, Gender, Country, City, AboutMe, Email)
VALUES
('$_GET[fname]','$_GET[lname]','$_GET[day], $_GET[month], $_GET[year]','$GET_[gender]','$_GET[country]','$_GET[city]','$_GET[aboutme]','$_GET[email]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
mysql_close($con)
?>
<?php
$name = $_GET['fname'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">First name: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['lname'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Last name: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['day'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Date </span>';
$name = $_GET['month'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">of </span>';
$name = $_GET['year'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">birth: </span>';
$name = $_GET['day'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
$name = $_GET['month'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
$name = $_GET['year'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['gender'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Gender: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['country'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">Country: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['city'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">City: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['aboutme'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">About me: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
<br />
<br />
<?php
$name = $_GET['email'];
echo '<span style="color:#E3E9F2;font-family:Courier New;font-size:13px;font-weight:bold;">E-mail: </span><span style="color:#EFF3F7;font-family:Courier New;font-size:13px;"> '.$name.' </span>';
?>
</body>
</html>
Now...the data from the "edit_profile.html (Edit Profile section)" is submitted into "my_profile.php" (My profile section) page and also into mysql db, but if i leave the "My profile" section and come back, the input data is gone from the page, remaining only in mysql db and every time i click "My profile" it creates a blank (unfilled with data) row in the mysql database. The important thing is, i need the data to be saved in "My profile" section after submitting the form and stay there all the time so the member/members can see it whenever he/they wants/want.
I searched the internet but found only "submit form to database" and "save form to a text file". I want my site to have a My profile like social sites: facebook, hi5, date sites, not so complex, a simple one, but to make an idea of what i need.
If someone can help with some scripts, ideas, guides, links, i'll really appreciate it. Every bit counts!
Looking forward to your replies. Thanks!