Save form data after submitting to a page within website

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
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Save form data after submitting to a page within website

Post by Blaade »

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!
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Save form data after submitting to a page within website

Post by Celauran »

Blaade wrote:i made a "edit_profile.html" form, which is submitted to "my_profile.php".
Why not just post it back to the same page?
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Save form data after submitting to a page within website

Post by Blaade »

Still won't be saved on the page...and it's better with an edit section and submitted to my profile section. Trying to figure it out for 2 days now...it's driving me crazy. I am doing the site with a web builder but still need some coding for some stuff, found what i needed until this problem. I don't know complex coding that's why i need some help.
temidayo
Forum Contributor
Posts: 109
Joined: Fri May 23, 2008 6:17 am
Location: Nigeria

Re: Save form data after submitting to a page within website

Post by temidayo »

Blaade wrote:Still won't be saved on the page...
Yes, it cannot be saved in your form. http connection is stateless.

You will always need to retrieve(recall) your data from the database each time
you need to display it again using an sql SELECT statement unless of course you are using a SESSION.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: Save form data after submitting to a page within website

Post by Celauran »

Sorry, misunderstood what you were asking. I thought this was about redisplaying $_POST data.
Blaade
Forum Commoner
Posts: 29
Joined: Tue Feb 28, 2012 8:44 am

Re: Save form data after submitting to a page within website

Post by Blaade »

I am using a web builder program to make a site but sometimes i need some scripts for more complex actions. I don't know complex coding and what scripts i need i take from the internet but this is the first serious problem that i bumped into and can't find a good script example. Thanks for the reply, i'll try to implement some stuff with SELECT based on other examples and see how it goes.
Post Reply