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
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/>';
}
?>

Link to comment
Share on other sites

Thanks that worked.

 

I know i said i could prepare update.php. but

 

can you help me with getting those id numbers to my edit.php page. I always used switch statements to define actions. how am going to do that?

 

can you give me example for editing "username" row?

Link to comment
Share on other sites

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 tommycrsuh@gmail.com and i'll get it to you.

 

Link to comment
Share on other sites

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
}
?>

 

 

Link to comment
Share on other sites

<?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?

Link to comment
Share on other sites

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">

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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 ";

Link to comment
Share on other sites

It's working now. But got a small problem.

 

I can't echo my values in text areas.

 

<br />Tour:<br /><textarea name="tour" value="<?php echo $tour; ?>" rows="30" cols="60"></textarea>

 

Nothing is wrong with my variable, it works out of textarea.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.