Jump to content

Using POST info on same page. + Updating rows with multiple fields.


RoninStretch

Recommended Posts

Hey all

 

Hope someone can help me here, just looking for some guidance.

 

I have a page that displays a users profile info from the database. However if a GET is assigned aswell i.e account.php?name=User then it displays that persons info.

I want it so that when the user is looking at his own profile he can edit it.

So i managed to make it show forms, filling them from his info.

the problem comes with processing the POST info and updating the database..

 

Here's what's relevant.

 

mysql_connect("localhost",$dbuser,$dbpass);
@mysql_select_db($dbname) or die( "Unable to select database" );

$posted=$_POST["usernamebox"];
if($posted==""){
}
else{
$user=$_POST["usernamebox"];
$email=$_POST["emailbox"];
$website=$_POST["websitebox"];
$picurl=$_POST["websitebox"];

@mysql_result(mysql_query("UPDATE users set username='$user' WHERE id='$id'"),0,0);
@mysql_result(mysql_query("UPDATE users set email='$email' WHERE id='$id'"),0,0);
@mysql_result(mysql_query("UPDATE users set website='$website' WHERE id='$id'"),0,0);
@mysql_result(mysql_query("UPDATE users set picurl='$picurl' WHERE id='$id'"),0,0);

}


$name=$_GET["name"];
if(!$name){
$query = "SELECT * FROM users WHERE id='$id'";
$editing = 1;
}
else{
$query = "SELECT * FROM users WHERE username='$name'";
$editing = 0;

}
$result = mysql_query($query);

mysql_close();

 

 

Some of the variables are just there so I can check it's actually going into the right state. Ignore them if theyre not used basically.

 

Next problem is updating the database.. I had to put all on mulitple lines to make it update anything. I was trying out the queries on in phpmyadmin and that's all i could get to work.

 

I know i'm doing most of it wrong, most likely. But please educate me :)

 

Thanks for any help.

 

- Stretch

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.