jonnytbh Posted March 23, 2014 Share Posted March 23, 2014 Hi guys basically struggling with the get function at the moment, its just a basica admin syustem for deleting users etc and thats the bit which is currently not working. This is my first php which displays all users in the database and then gives the option next to them to delete, config.php automatically connects to the database.<?phpinclude "config.php";$db_name="unn_w13030935"; // Database name$tbl_name="users"; // Table name// select all records from mysql$sql= "SELECT * FROM $tbl_name";$result=mysql_query($sql);?><table width="400" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC"><tr><td colspan="5" bgcolor="#FFFFFF"><strong>USER MANAGEMENT</strong> </td></tr><tr><td align="center" bgcolor="#FFFFFF"><strong>Member id</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Name</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Lastname</strong></td><td align="center" bgcolor="#FFFFFF"><strong>Email</strong></td><td align="center" bgcolor="#FFFFFF"><strong>D.O.B</strong></td></tr><?phpwhile($rows=mysql_fetch_array($result)){?><tr><td bgcolor="#FFFFFF"><? echo $rows['id_user']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['user_name']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['pwd_hash']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['email']; ?></td><td bgcolor="#FFFFFF"><? echo $rows['date_birth']; ?></td><td bgcolor="#FFFFFF"><a href="delete2.php?id=<? echo $rows['id_user']; ?>">delete</a></td><td bgcolor="#FFFFFF"><a href="changepassword.php?id=<? echo $rows['id_user']; ?>">change password</a></td><td bgcolor="#FFFFFF"><a href="?id=<? echo $rows['id_user']; ?>">edit</a></td><td bgcolor="#FFFFFF"><a href="?id=<? echo $rows['id_user']; ?>">ban user</a></td></tr><?php// close while loop}?></table> This is my second file for deleting which should delete a user row based on the user_id when the delete is clicked<?phpinclude "config.php";$db_name="unn_w13030935"; // Database name$tbl_name="users"; // Table name// get value of id that sent from address bar$id_user=$_GET['id_user'];// Delete data in mysql from row that has this id$sql="DELETE FROM $tbl_name WHERE id_user='$id_user'";$result=mysql_query($sql);// if successfully deletedif($result){echo "Deleted Successfully";echo "<BR>";echo "<a href='delete1.php'>Back to User Management</a>";}else {echo "ERROR";}?><?php// close connectionmysql_close();?> I am currently getting a "Notice: Undefined index: id_user in /var/www/vhosts/numyspace.co.uk/web_users/home/~unn_w13030935/public_html/delete2.php on line 9Deleted Successfully" and it does not delete, line 9 " $id_user=$_GET['id_user']; " i do not understand how this line is the error as it should be working.Can anyone help me out here? Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 23, 2014 Share Posted March 23, 2014 You are passing the users user_id via a query string parameter called id not id_user <td bgcolor="#FFFFFF"><a href="delete2.php?id=<? echo $rows['id_user']; ?>">delete</a></td> You should be using $_GET['id'] in delete2.php when retrieving the users id Quote Link to comment Share on other sites More sharing options...
jonnytbh Posted March 23, 2014 Author Share Posted March 23, 2014 Thanks that has now gotten rid of the indefined index problem but it is not actually deleting from the database and just giving me my "ERROR" for the error message does this mean there is a problem with the SQL query as im sure that is correct for deleting, delete2.php is now:include "config.php";$db_name="unn_w13030935"; // Database name$tbl_name="users"; // Table name// get value of id that sent from address bar$id=$_GET['id'];// Delete data in mysql from row that has this id$sql="DELETE FROM $tbl_name WHERE id='$id'";$result=mysql_query($sql);// if successfully deletedif($result){echo "Deleted Successfully";echo "<BR>";echo "<a href='delete1.php'>Back to User Management</a>";}else {echo "ERROR";}?> ThanksJonny Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted March 23, 2014 Share Posted March 23, 2014 me my "ERROR" for the error message does this mean there is a problem with the SQL query Yes, to see what the error is use mysql_error() 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.