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

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.