hi i am fairly new to php/mysql i have this program that does not want to delete from the database. at first it was telling me that the file had been delete and when i checked the database it was still there. no i get two different errors depending on what i do to the code.
the delete code
Code:
<?PHP
ini_set('display_errors', 1);
error_reporting(E_ALL);
include 'mysqlconnectsitel.inc.php';// this has my database connection stuff
if($_GET['m'] == 'del' )// one error i get is right here
{
$requestId = $_GET['id'];
//$last=$_GET['last'];
//$first=$_GET['first'];
$query ="DELETE FROM timeoff WHERE requestId = '$requestId' ";// if i change this to last ='$last' AND first ='$first' o get undefined variables not pulling the data
$result= mysql_query($query) or die(mysql_error());
echo" <center><font color=\"#000000\">Your Info Was Deleted!</font></center> ";
echo "<p><strong>To start at the begining page.<a href='members.php'>Click here</a></strong></p>";
echo "<p><strong>To check your dates again.<a href ='checkdates.php'>Click here</a></strong></p>";
}
else{
echo "No selection was made. please try again.";
echo "<p><strong>To start at the begining page.<a href='members.php'>Click here</a></strong></p>";
echo "<p><strong>To check your dates again.<a href ='checkdates.php'>Click here</a></strong></p>";
}
?>
this code is activated from a link on a page that has check boxes and a link for delete that uses this. please help have been trying for a few days to get this.
Notice: Undefined index: m in C:\apache2triad\htdocs\index.php on line 7 No selection was made. please try again.
i did have something selected
right now cause i just tried it, the above error is all that i am getting
i fixed the error i took that out a replaced it with something else, but now when i run it a check a ckeck box hit delete link it say no selection was made.
Last edited by amylou111770; 08-30-2007 at 12:15 AM..
Reason: fixed that error
Are you POST'ing the form? <form method="post"
If so, you should be using $_POST instead of $_GET.
If not, your variable isn't being passed in the URL or isn't the correct name.
Well, that delete link isn't going to do anything because it's just passing "id" as the query string. If you want to use checkboxes you have to provide each with the id of the MySQL row you want to remove. ie.
PHP Code:
echo '<td><input type="checkbox" name="deleted_items[' . $row['id'] . ']" />'; // just noticed you didn't close your tag either
And loop through them on the next page. $_POST['deleted_items'] should be an array of the checkboxes that were checked(or nothing if none were checked).
PHP Code:
if(!empty($_POST['deleted_items'])) { foreach($_POST['deleted_items'] as $id => $on) { $query = 'DELETE FROM `table` WHERE `id` = ' . $id; // mysql_query() } }
while($row = mysql_fetch_assoc($query)) { echo '<p>' . $row['first'] . ' ' . $row['last'] . ' ' . $row['requestedDate']; echo '<td><input type="checkbox" name="deleted_items[' . $row['id'] . ']" />'; // I put "id" here, you need to change this to your id field, and make sure you select it in your query echo '</p>'; } ?>
Ok, so $requestId isn't being set on the delete page. Did you make that loop I posted earlier? Post the delete page.
Also, look at the source of the page with the checkboxes and see if there are numbers in the name="deleted_items[#]". Post that page too if there aren't any numbers. If there are numbers then all we need to fix is the loop on the delete page.