Jump to content

Edit member profile link


eleven0

Recommended Posts

I have members table where i store my members info and etc.

 

I'm preparing an admin section to manage all of my members.

 

In my admin index page, I list all of my members by using mysql and php. I want to put "Edit profile" link next to their names. When you click on, it will open a window where you can edit that profile. I can prepare a "Update.php" page by using forms and all. But how do i make it automatic? so when I add a new member to that table, it will automatically put the edit link next to their name.

 

and yes i do use "id" in my table.

 

what would be the easiest for me to do this?

Link to comment
https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/
Share on other sites

if i understand what you're trying to do, then its easy

well you use php and mysql

 

<?php
$result = mysql_query("SELECT `id`, `username` FROM `table`")
while($row = mysql_fetch_row($result)){ // its either this or "mysql_fetch_assoc($result)"
echo 'Member: '.$row['username'];
echo '<a href="edit_profile.php?id='.$row['id'].'">Edit Profile<a/>';
}
?>

well this line right here:

echo '<a href="edit_profile.php?id='.$row['id'].'">Edit Profile<a/>';

will direct you to edit_profile.php?id=the id of the user

 

so you will grab that info from the url.

its a certain code, and i'm not sure what it is, and i'm not at my home computer, so i don't know exactly what it is right now.

 

But after you grab the url info, you would do something like this:

$id = sql_quote['id'];

$id = mysql_real_escape_string($id); // helps protect against injections

$result = mysql_query("SELECT * FROM `table` WHERE `id` = '{$id}' ")

 

i won't email to send the code later, so email me at [email protected] and i'll get it to you.

 

EDIT: fixed a few things.....

 

anyways,

 

echo '<a href="edit_profile.php?id='.$row['id'].'">Edit Profile<a/>';

will direct you to edit_profile.php?id=the id of the user

 

on the edit page, you would have this code...

<?php
function sql_quote($data) {
  if (get_magic_quotes_gpc()) {
  $data = stripslashes($data);
  }

return addslashes($data);
}
$id = sql_quote($_GET['id']);
$action = sql_quote($_GET['action']);
//connect to database
$id = mysql_real_escape_string($id); // helps protect against injections
$result = mysql_query("SELECT * FROM `table` WHERE `id` = '{$id}' ")

?>
//then display all the user info code in text areas,
<form action="edit_profile.php?action=edit>
<textarea rows="10" cols="20" name="email" value="<?php echo $email ?>">
</textarea>
<input type="submit" name="submit" value="save"/>
</form>
<?php
if($action == 'edit'){
mysql query to save all that info
}
?>

 

 

<?php
function sql_quote($data) {
  if (get_magic_quotes_gpc()) {
  $data = stripslashes($data);
  }

return addslashes($data);
}
$id = sql_quote($_GET['id']);
$action = sql_quote($_GET['action']);
include 'config.php';
include 'opendb.php';
$id = mysql_real_escape_string($id); // helps protect against injections

	$query = "SELECT * FROM `members` WHERE `id` = '{$id}' "; 

	$result = mysql_query($query) or die(mysql_error());

$name=$row['name'];
$rank=$row['rank'];
$lastname=$row['lastname'];
$pos=$row['pos'];
$s=$row['squad'];
$asn=$row['asn'];
$tour=$row['tour'];





?>

<form name="update" action="edit_profile.php?action=edit method="post">
Name:<input type="text" name="name" value="<?php print $name; ?>"/>
Last name:<input type="text" name="lastname" value="<?php print $lastname; ?>"/>
Rank:<input type="text" name="rank" value="<?php print $rank; ?>"/>
Pos:<input type="text" name="pos" value="<?php print $pos; ?>"/>

<input type="submit" name="submit" value="save"/>
</form>

 

It's not getting the values from database and put them into text fields.

 

What am i doing wrong?

well you never defined what "row" means....

you forgot this:

 

$row = mysql_fetch_array($result);

 

try and see if that does it.

 

and in this:

<form name="update" action="edit_profile.php?action=edit method="post">

 

you forgot a " .....needs to be this:

<form name="update" action="edit_profile.php?action=edit" method="post">

<?php
function sql_quote($data) {
  if (get_magic_quotes_gpc()) {
  $data = stripslashes($data);
  }

return addslashes($data);
}
$id = sql_quote($_GET['id']);
$action = sql_quote($_GET['action']);
include 'config.php';
include 'opendb.php';
$id = mysql_real_escape_string($id); // helps protect against injections

	$query = "SELECT * FROM `members` WHERE `id` = '{$id}' "; 
	$result = mysql_query($query) or die(mysql_error());
	$row = mysql_fetch_array($result);

$name=$row['name'];
$rank=$row['rank'];
$lastname=$row['lastname'];
$pos=$row['pos'];
$s=$row['squad'];
$asn=$row['asn'];
$tour=$row['tour'];
?>

<form name="update" action="edit_profile.php?action=edit" method="post">
Name:<input type="text" name="name" value="<?php print $name; ?>"/>
Last name:<input type="text" name="lastname" value="<?php print $lastname; ?>"/>
Rank:<input type="text" name="rank" value="<?php print $rank; ?>"/>
Pos:<input type="text" name="pos" value="<?php print $pos; ?>"/>

<input type="submit" name="submit" value="save"/>
</form>

 

Still not working and not giving me an error either.

first is your members table names members or another thing ( like users ), if other than members then change ( SELECT * FROM `members`) to ( SELECT * FROM `TABLE_NAME_HERE` )

 

can you just delete the { & } from this line and give it a try

 

from

	$query = "SELECT * FROM `members` WHERE `id` = '{$id}' ";

 

to

	$query = "SELECT * FROM `members` WHERE `id`='$id' ";

 

BTW, if your ID coulmn in the db is numeric ( normally ID's are INT ), then you may want to remove the single qutation to so you will use

 

	$query = "SELECT * FROM `members` WHERE `id`=$id ";

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.