eleven0 Posted March 8, 2008 Share Posted March 8, 2008 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 More sharing options...
ohdang888 Posted March 8, 2008 Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-486667 Share on other sites More sharing options...
eleven0 Posted March 8, 2008 Author Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-486741 Share on other sites More sharing options...
ohdang888 Posted March 8, 2008 Share Posted March 8, 2008 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. Link to comment https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-486766 Share on other sites More sharing options...
eleven0 Posted March 8, 2008 Author Share Posted March 8, 2008 k thanks..... Can someone else help me with my second question? Link to comment https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487247 Share on other sites More sharing options...
ohdang888 Posted March 8, 2008 Share Posted March 8, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487297 Share on other sites More sharing options...
eleven0 Posted March 9, 2008 Author Share Posted March 9, 2008 <?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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487374 Share on other sites More sharing options...
ohdang888 Posted March 9, 2008 Share Posted March 9, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487405 Share on other sites More sharing options...
eleven0 Posted March 9, 2008 Author Share Posted March 9, 2008 <?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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487439 Share on other sites More sharing options...
Xajel Posted March 9, 2008 Share Posted March 9, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487448 Share on other sites More sharing options...
ohdang888 Posted March 9, 2008 Share Posted March 9, 2008 echo $query and see what you're even searching for is right. Link to comment https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487457 Share on other sites More sharing options...
eleven0 Posted March 9, 2008 Author Share Posted March 9, 2008 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 https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487494 Share on other sites More sharing options...
eleven0 Posted March 9, 2008 Author Share Posted March 9, 2008 lol nevermind fixed... Thanks for help. Link to comment https://forums.phpfreaks.com/topic/95008-edit-member-profile-link/#findComment-487502 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.