Bradster Posted May 6, 2008 Share Posted May 6, 2008 Ok I am looking into admin panels and how they work, I have made a functioning admin panel that can, so far, delete members, add members, login and logout. The problem I have is updating information. http://82.13.153.175/aoc/admin/index.php Username: Stephen, Password: qwerty I have given you this link so I can explain to you in more detail what is happening. Go to the Add / Edit Members page and you will see a list of members and an add member section underneath. When you click update, it takes you to the member you wish to edit, the url looks like this; http://82.13.153.175/aoc/admin/index.php?page=members_update&id=4 Or something similar, when you change the information and click Update I made it so it says, you have successfully updated the member, blah blah blah, so you can see that it is updating, although it does not show an ID number, which is how I know it is not working. It should display the ID. This is the code for the update page; <? include('login_check.php'); include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <form method="post" action="members_update_ac.php"> <table> <tr> <td class="header">Username</td><td class="header">Password</td><td class="header">Email</td> </tr> <tr> <td><input type="text" name="username" id="username" value="<? echo $rows['username']; ?>"></td><td><input type="password" name="password" id="password" value="<? echo $rows['password']; ?>"></td><td><input type="text" name="email" id="username" value="<? echo $rows['email']; ?>"></td> </tr> <tr> <td colspan="3" class="header">Profile</td> </tr> <tr> <td colspan="3"><textarea name="profile" id="profile" cols="60" rows="6"><? echo $rows['profile']; ?></textarea></td> </tr> <tr> <td colspan="3"><input type="hidden" name="id" id="id" value="<? echo $rows['id']; ?>"><input type="submit" value="Update"></td> </tr> </table> </form> <? mysql_close(); ?> And here is the code for the update processing page; <?php include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET username='$username', password='$password', email='$email', profile='$profile' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successfully updated information to ".$id; } else { echo "Error"; } ?> Thanks in advance if you can help me. Quote Link to comment Share on other sites More sharing options...
burnside Posted May 6, 2008 Share Posted May 6, 2008 as far as i can see if the <?php include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET username='$username', password='$password', email='$email', profile='$profile' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successfully updated information to ".$id; } else { echo "Error"; } ?> Is for the members_prossesing_ac.php or what ever the name is, there is no $_GET['id'] set. so try sumit like this : <?php include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); $id = $_GET['id']; // ADDED THIS // update data in mysql database $sql="UPDATE $tbl_name SET username='$username', password='$password', email='$email', profile='$profile' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successfully updated information to ".$id; } else { echo "Error"; } ?> Quote Link to comment Share on other sites More sharing options...
Bradster Posted May 6, 2008 Author Share Posted May 6, 2008 Thanks for the reply but it does not work :S, any other ways to fix this? . Quote Link to comment Share on other sites More sharing options...
burnside Posted May 6, 2008 Share Posted May 6, 2008 in your form method your using POST is should be GET sorry didn't spot it b4. Quote Link to comment Share on other sites More sharing options...
Bradster Posted May 6, 2008 Author Share Posted May 6, 2008 Still doesnt work lol :-\ Quote Link to comment Share on other sites More sharing options...
burnside Posted May 6, 2008 Share Posted May 6, 2008 haha if no one has helped you ill take another look when i get home, im currently at work. Quote Link to comment Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hey burnside, this is most likely a long shot, but has the hidden field 'id' in the form definately have the id of the user? also i saw your forms method is now 'post', so when you get the value on the process page it must also be post. so, basically on the process page you should have <?PHP //.... $id = $_POST['id']; //... ?> if you want me to post the entire code then just shout, it may make more sense then Quote Link to comment Share on other sites More sharing options...
Bradster Posted May 6, 2008 Author Share Posted May 6, 2008 So basically what you are saying is that on the process page I need to have; $id = $_GET[id]; On there and on the form on the main update page I need to have this in the method and post; <form method="post" action="members_update_ac.php?id=<? echo $rows[id]; ?>"> Is that right? I'll try it anyway, post the whole code please if it doesnt work . Quote Link to comment Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hey, sorry. below is the form and the process page: FORM <?php <? include('login_check.php'); include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $sql="SELECT * FROM $tbl_name WHERE id='$id'"; $result=mysql_query($sql); $rows=mysql_fetch_array($result); ?> <form method="post" action="members_update_ac.php"> <table> <tr> <td class="header">Username</td><td class="header">Password</td><td class="header">Email</td> </tr> <tr> <td><input type="text" name="username" id="username" value="<? echo $rows['username']; ?>"></td><td><input type="password" name="password" id="password" value="<? echo $rows['password']; ?>"></td><td><input type="text" name="email" id="username" value="<? echo $rows['email']; ?>"></td> </tr> <tr> <td colspan="3" class="header">Profile</td> </tr> <tr> <td colspan="3"><textarea name="profile" id="profile" cols="60" rows="6"><? echo $rows['profile']; ?></textarea></td> </tr> <tr> <td colspan="3"><input type="hidden" name="id" id="id" value="<? echo $rows['id']; ?>"><input type="submit" value="Update"></td> </tr> </table> </form> <? mysql_close(); ?> PROCESS PAGE <?php include('../db/dbconnect.php'); //here is what i added $id = $_POST['id']; echo "ID EDITED - ".$id; $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET username='$username', password='$password', email='$email', profile='$profile' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successfully updated information to ".$id; } else { echo "Error"; } ?> Quote Link to comment Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hey, really sorry. i miss read the form page: on a call quick and will post back to you now! sorry again Quote Link to comment Share on other sites More sharing options...
Bradster Posted May 6, 2008 Author Share Posted May 6, 2008 Right, well what I have done what you have said in the main update and processing page. When I click update it shows the information for that ID, but when I change it and click update it changes the username to "root" and the other information is deleted. Thanks Saint, awaiting reply. Quote Link to comment Share on other sites More sharing options...
burnside Posted May 6, 2008 Share Posted May 6, 2008 for your update query. $profile $username $password all will need to be defined by $_POST['var']; i think. Quote Link to comment Share on other sites More sharing options...
saint959 Posted May 6, 2008 Share Posted May 6, 2008 hi, FORM <?php include('login_check.php'); include('../db/dbconnect.php'); $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // get value of id that sent from address bar $id=$_GET['id']; // Retrieve data from database $res = mysql_query("SELECT * FROM `$tbl_name` WHERE `id` = '$id'"); if ($r = mysql_fetch_assoc($res)) { $tab_user = $r['username']; $tab_pass = $r['password']; $tab_email = $r['email']; $tab_prof = $r['profile']; $tab_id = $r['id']; } else { print "error getting details"; } mysql_close(); ?> <form method="post" action="members_update_ac.php"> <table> <tr> <td class="header">Username</td><td class="header">Password</td><td class="header">Email</td> </tr> <tr> <td><input type="text" name="username" value="<? echo $tab_user; ?>"></td><td><input type="password" name="password" value="<? echo $tab_pass; ?>"></td><td><input type="text" name="email" value="<? echo $tab_email; ?>"></td> </tr> <tr> <td colspan="3" class="header">Profile</td> </tr> <tr> <td colspan="3"><textarea name="profile" id="profile" cols="60" rows="6"><? echo $tab_prof; ?></textarea></td> </tr> <tr> <td colspan="3"><input type="hidden" name="id" id="id" value="<? echo $tab_id; ?>"><input type="submit" value="Update"></td> </tr> </table> </form> PROCESS PAGE <?php include('../db/dbconnect.php'); $username = $_POST['username']; $password = $_POST['password']; $email = $_POST['email']; $profile = $_POST['profile']; $id = $_POST['id']; print $id." - ".$username." - ".$password." - ".$email." - ".$profile; $db_name="anon"; // Database name $tbl_name="members"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect"); mysql_select_db("$db_name")or die("cannot select DB"); // update data in mysql database $sql="UPDATE $tbl_name SET username='$username', password='$password', email='$email', profile='$profile' WHERE id='$id'"; $result=mysql_query($sql); // if successfully updated. if($result){ echo "Successfully updated information to ".$id; } else { echo "Error"; } ?> im printing all te variables just so you can be sure that everything is coming through. hope this helps Quote Link to comment Share on other sites More sharing options...
Bradster Posted May 6, 2008 Author Share Posted May 6, 2008 for your update query. $profile $username $password all will need to be defined by $_POST['var']; i think. Dude, you and Saint are a god send. I got it working. In the process page I did neet to put; $id = $_POST['id']; But I also needed to define the $_POST's as Burnside said from the previous. Thanks guys so much, been working on this one all day . EDIT: Just read the re-post by Saint, yeah thats what I did, thanks again for the help. Quote Link to comment Share on other sites More sharing options...
burnside Posted May 6, 2008 Share Posted May 6, 2008 No problem glad to help Edit : Now you just need to sanatize your inputs i have just redirected your site to google. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.