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!
Save form data after submitting to a page within website
Moderator: General Moderators
Re: Save form data after submitting to a page within website
Why not just post it back to the same page?Blaade wrote:i made a "edit_profile.html" form, which is submitted to "my_profile.php".
Re: Save form data after submitting to a page within website
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.
Re: Save form data after submitting to a page within website
Yes, it cannot be saved in your form. http connection is stateless.Blaade wrote:Still won't be saved on the page...
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.
Re: Save form data after submitting to a page within website
Sorry, misunderstood what you were asking. I thought this was about redisplaying $_POST data.
Re: Save form data after submitting to a page within website
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.