Login | Register | FAQ
Anonymous

PHP edit profile ERROR!

+ Post a reply

4 posts Page 1 of 1


PHP edit profile ERROR!

by soccerwebsitemaker » Sun Jun 10, 2012 5:53 pm

Ok, so I am making a website:

One page is called profile.php, this displays where your info is according to stuff on a database.

The next page is called profileedit.php, this is where you can change the info on the database. So far, I am having a problem, the data does not get submitted to the database no matter what.


Can anyone help me again?








Profile.php (the part where database info is displayed)









$prevcontent1 = $_POST['content-1'];

$prevcontent2 = $_POST['content-2'];

$prevcontent3 = $_POST['content-3'];

$prevcontent4 = $_POST['content-4'];

$prevcontent5 = $_POST['content-5'];

$prevcontent6 = $_POST['content-6'];

$prevcontent7 = $_POST['content-7'];

$profSTRsql = "UPDATE Profile_Info SET Content 1='$prevcontent1', Content 2='$prevcontent2', Content 3='$prevcontent3', Content 4='$prevcontent4', Content 5='$prevcontent5', Content 6='$prevcontent6', Content 7='$prevcontent7' WHERE Username='$username'";

mysql_query($profSTRsql, $connection);






while ($row4 = mysql_fetch_array($rs4)){

$content1 = $row4["Content 1"];

$content2 = $row4["Content 2"];

$content3 = $row4["Content 3"];

$content4 = $row4["Content 4"];

$content5 = $row4["Content 5"];

$content6 = $row4["Content 6"];

$content7 = $row4["Content 7"];

}





<h4 id="content-1-subheading">General Info</h4>

<p id="content-1">' . $content1 . '</p>

<h4 id="content-2-subheading">What ' . $username . ' likes</h4>

<p id="content-2">' . $content2 . '</p>





















Now, for profileedit.php



























while ($row4 = mysql_fetch_array($rs4)){

$content1 = $row4["Content 1"];

$content2 = $row4["Content 2"];

$content3 = $row4["Content 3"];

$content4 = $row4["Content 4"];

$content5 = $row4["Content 5"];

$content6 = $row4["Content 6"];

$content7 = $row4["Content 7"];

}










<form id="profileeditform" method="post" action="profile.php">

<h4 id="content-1-subhead">Edit your general info</h4>

<input type="text" value="' . $content1 . '" id="content-1" name="content-1" />

<h4 id="content-2-subhead">Edit your likes</h4>

<input type="text" value="' . $content2 . '" id="content-2" name="content-2" />

<h4 id="content-3-subhead">Edit your dislikes</h4>

<input type="text" value="' . $content3 . '" id="content-3" name="content-3" />

<h4 id="content-4-subhead">Edit your hobbies</h4>

<input type="text" value="' . $content4 . '" id="content-4" name="content-4" />

<h4 id="content-5-subhead">Edit your message</h4>

<input type="text" value="' . $content5 . '" id="content-5" name="content-5" />

<h4 id="content-6-subhead">Edit your family info</h4>

<input type="text" value="' . $content6 . '" id="content-6" name="content-6" />

<h4 id="content-7-subhead">Edit your education level</h4>

<input type="text" value="' . $content7 . '" id="content-7" name="content-7" />

<input type="submit" value="Done" id="profileeditsubmit" />

</form>











Thank you for reviewing this code...
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP edit profile ERROR!

by XainPro » Mon Jun 11, 2012 12:28 pm

On Profile Page you are getting/retrieving the data from the database am i right and you are trying to send all the data from profile page to profile edit page for the purpose of editing aren't you ?
well if you do then do not do it like this just send a unique code like user_id from profile page to profile editing page and retrieve all the data from database again on the basis of that id
like i.e
select * from users where user_id = $_POST['user-id']
and then edit it like you do add or update on the time of new user registration actually use same code just update the query this time replace the insert into with update set etc.
i hope you understand what i am trying to explain if not then please ask me i will explain further.
User avatar

XainPro

  • Posts: 3669
  • Joined: Fri Feb 17, 2012 8:10 pm

Re: PHP edit profile ERROR!

by soccerwebsitemaker » Mon Jun 11, 2012 9:28 pm

Well, hey, I figured out the situation.

In profile.php, when I $_POST the values, it works...

but it only works when the previous page I visited was profileedit.php

Otherwise, if i go to a different page, it posts an empty value, updates that empty value, and then echoes that empty value!

How do I lose my dependence on $_POST because it works only when I leave the profileedit page, but not for a different page?





*EDIT* Ok, I figured it out...After going to profileedit, you click done and it takes you to profileeditdone.php (note visitors are not supposed to go to this page unless after they submit the form, or they'll erase all their data because of the empty $_POST values) , where data is $_POSTED and updated into the database. Then, you can go to profile.php and the only thing that happens there is that the data is selected from the database!

Does that work?
User avatar

soccerwebsitemaker

  • Posts: 139
  • Joined: Sat Dec 31, 2011 6:25 pm
--
Coins. Profile. Games. Chat. Fun.

CoinAwards.

Check it out at http://www.coinawards.net63.net/

Re: PHP edit profile ERROR!

by XainPro » Tue Jun 12, 2012 4:44 am

well do not be depended on $_POST

Simple strategy is user can only edit it's profile if he is logged in When user logged IN at the login form set a $_SESSION variable and save user_id in session and on any page you want to retrieve user info for any purpose either its for editing or showing etc use the query based on your session
like
select * from users where user_id = $_SESSION[user_id]
i hope you understand ...
User avatar

XainPro

  • Posts: 3669
  • Joined: Fri Feb 17, 2012 8:10 pm


+ Post a reply

Page 1 of 1