Jump to content

Help with GET function


jonnytbh

Recommended Posts

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.

<?php

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

<?php
while($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

<?php
include "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 deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='delete1.php'>Back to User Management</a>";
}

else {
echo "ERROR";
}
?>

<?php
// close connection
mysql_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 9
Deleted 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?

Link to comment
https://forums.phpfreaks.com/topic/287204-help-with-get-function/
Share on other sites

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 deleted
if($result){
echo "Deleted Successfully";
echo "<BR>";
echo "<a href='delete1.php'>Back to User Management</a>";
}

else {
echo "ERROR";
}
?>

 

Thanks
Jonny

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.