Jump to content

[SOLVED] problem deleting


amylou

Recommended Posts

i have also posted in the mysql forum not sure which place would be the right one. I finally got the program to show the results with check boxes and a link for delete. when the user hits the delete button it will tell them that the selected items have been deleted but when checking the database it is still there.

checkdates.php is the code for checking and seeing the results

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<?php
/*this program was designed to eliminate paper work for the sift supervisors and the csps that work at Sitel here at loring.
  this program was written and developed by Amy Coppola on July 2007	
*/	
?>
<?php 
include'mysqlconnectsitel.inc.php'; 
?>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Check The Dates</title>
<link href= "links.css" rel="stylesheet" type="text/css"/>
<link href= "general.css" rel="stylesheet" type="text/css"/>

<?php 
function getmonth($m=0) {
return (($m==0 ) ? date('F') : date('F', mktime(0,0,0,$m)));
}
?>

</head>
<body>
<br>

<img src="33720001.jpg" alt="sitel" width="300" height="100" />

<?php
if(isset($_POST['action'])){$action=$_POST['action'];}else{$action="";}
if( $action == 'updated' )
{
  extract ($_POST);
  $todaysDate = date("Y-m-d",time());
  
        

//	Need to query database to see if this request is valid


echo "<p><strong>These are the dates that you have requested off!!!!</strong></p>";


$sql ="SELECT first, last, requestedDate FROM timeoff WHERE last = '$last' AND first = '$first'";
$query=mysql_query($sql) or die("Query failed : " . mysql_error());
while($row = mysql_fetch_assoc($query)) {
echo "<p>";
echo $row['first'] ." ". $row['last']. " ". "  ". $row['requestedDate'];	
echo "<td><input type=\"checkbox\" name=\"deleted_items[]\" "; 
echo "</p>";
}
        
$action="";
$_html ="<tr> 
    <td>$_rw->requestId</td>
    <td>$_rw->first</td>
<td>$_rw->last</td>
<td>$_rw->requestedDate</td>
     <td>
   <a href=\"index.php?id=$_rw->requestId&m=del\">DELETE </a></td>

    </tr>";
echo $_html;
echo "<p><strong>To start at the begining page.<a href='members.php'>Click here</a></strong></p>";
}
else

{
  
  
?>

  <form name='checkdate' method='post' action='checkdates.php'> 
<table width="500" border="0">
    <tr>   
    <td>First Name </td>
    <td><input name="first" type="text" size="20" maxlength="20"></td>
  </tr>
  <tr>
    <td>Last Name </td>
    <td><input name="last" type="text" size="30" maxlength="30"></td>
  </tr>
    
  <tr><td><b>Todays Date:</b></td>
  <td>
   <?php
$todaysDate = date("m-d-Y",time());
echo "$todaysDate";	
?> 
  </td>
</tr> 
          
<tr><td colspan="2" align="center">
<input type= 'hidden' name= 'action' value= 'updated'>					
  		<input type = "submit" name = "submit" value= "Submit">
  </td></tr></table>
  
</form>
<?php
}
?>
</body>
</html>

 

index.php has the delete code

<?php
/*this program was designed to eliminate paper work for the sift supervisors and the csps that work at Sitel here at loring.
  this program was written and developed by Amy Coppola on July 2007	
*/	
?>

<?PHP

include 'mysqlconnectsitel.inc.php';// this has my database connection stuff
if($_GET['m'] == 'del' )
{
$requestId = $_GET['id'];
   $query ="DELETE  FROM timeoff WHERE requestId = '$requestId'";
  $result= mysql_query($query) or die(mysql_error());
   echo" <center><font color=\"#00CC00\">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>";
?>


</body>
</html>

 

if this can be done easier i would like that. i know that this is going to be a dumb newbbe mistake but i just can not find it

Link to comment
Share on other sites

I believe you need a *.

$query ="DELETE * FROM timeoff WHERE requestId = '$requestId'";

 

I didn't know you could do that without getting a syntax error. I guess it assumes "delete nothing from.."

 

No, thats wrong. In a delete query you tell the database what to delete in the WHERE clause.

 

I am looking over the code, give me a sec to reply =]

Link to comment
Share on other sites

tried that and i get the following error

 

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '* FROM timeoff WHERE requestId = ''' at line 1

 

and the line of code that its pertaining to is:

 $query ="DELETE * FROM timeoff WHERE requestId = '$requestId'"; 

 

any other suggestions

Link to comment
Share on other sites

 

<?php
/*this program was designed to eliminate paper work for the sift supervisors and the csps that work at Sitel here at loring.
  this program was written and developed by Amy Coppola on July 2007	
*/	
?>

<?php

include 'mysqlconnectsitel.inc.php';// this has my database connection stuff
if($_GET['m'] == 'del' )
{
$requestId = $_GET['id'];
   $query ="DELETE  FROM timeoff WHERE requestId = '$requestId'";
  $result= mysql_query($query) or die(mysql_error());
 $affrows = mysql_affected_rows();
 if ($affrows > 0) {
       echo" <center><font color=\"#00CC00\">Your Info Was Deleted!</font></center> "; 
 } else {
      // error
 }
}

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>";
?>


</body>
</html>

 

 

I've edited your code to check whether it actually did delete the rows or not. My part is just after your query.

 

Just to clarify, you do NOT need a '*'.

Link to comment
Share on other sites

Your right, the double white-spaces confused me and made me think there was supposed to be something there. Is the requestId field a string? If not, you don't need the apostrophes (I actually think that would give an error, so it probably is a string.) Other than that, the query is fine. The only reason it wouldn't delete is if $requestId wasn't found in the requestId fields anywhere.

Link to comment
Share on other sites

Your code is kinda hard to work off of, so I am going to give you an example of how you would do it.

 

<?php

//If they press delete
if (isset($_POST['submit'])){
   foreach ($_POST['selected'] as $key){
      $query = "DELETE FROM timeoff WHERE requestId = '$key'";
      mysql_query($query)or die(mysql_error());
    }
}

//This is what your checkboxes code should look like.
echo "<form method='POST' action='somewhere.php'>";

while ($row = mysql_fetch_assoc($some_query)){
   echo "<input type='checkbox' name='selected[]' value='{$row['unique_ID']}'>";
}

echo '<input type="submit" name="submit">';
echo '</form>';

?>

 

This is untested, but it should work.

 

 

 

Link to comment
Share on other sites

Make sure it isn't a double space, just 1.

 

Secondly, Create an error reoprting sytem where I put "// error"

 

echo the $query and mysql_error();

 

This will show you whether there is a problem with passing the variable or if it's a MySQL issue.

Link to comment
Share on other sites

His code was just supposed to hide the error if it didn't find anything to delete. You should put an "echo $requestId" before your query and see if it is in your database.

 

My code was for her to put her own error message in, whatever she thought was the easiest way to debug her script. In my previous script, I have put the way I do it but that may not be the best way for everybody.

Link to comment
Share on other sites

requestId is an auto incremented number in the database to use as primary key in database.

 

Have you tried to replace the "//error" with something to actually report the errors? echo the $query and mysql_error(). Copy and paste the results here although you may notice any errors yourself.

Link to comment
Share on other sites

Have you tried to replace the "//error" with something to actually report the errors? echo the $query and mysql_error(). Copy and paste the results here although you may notice any errors yourself.

 

i did this no errors just a white page after hitting the delete link

Link to comment
Share on other sites

Do you have error reporting on? I mean if there is an error in your script such as a missing quotation mark or something, do you get an error?

 

On my old server I never used to get errors reported and always resulted in a blank screen. View the source and see if it is an HTML problem.

Link to comment
Share on other sites

yes i have error reporting on and no errors. i checked the source code of the blank page and there is nothing there except the following

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<HTML><HEAD>

<META http-equiv=Content-Type content="text/html; charset=iso-8859-1"></HEAD>

<BODY></BODY></HTML>

 

so some where it is not registering

Link to comment
Share on other sites

That's what I used to get. Thoroughly check through your script for any errors. If possible, switch to a different server, preferably linux.

 

If you don't want to do that, just keep putting lots of things in such as commenting out sections of your script and narrowing down where an error may lie. You could also put after each bracket a number then exit();. This will tell you how far the script is getting before theres an error.

Link to comment
Share on other sites

okay i have been looking and i don't think i have the correct error reporting function thing going. could you tell me where its at so that i might be able to see

 

also i don't have access to another server to test it to see if it works

Link to comment
Share on other sites

i have turned on the error reporting in my php.ini file,

 

and i tried the following code to make sure it worked

<?php
print("The next line generates an error.<br>");
printaline("PLEASE?");
print("This will not be displayed due to the above error.");
?>

 

and the only thing that worked on it was the first line---print("the next line generates and error.<be>");

 

and i am still not getting any errors when i run my program

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.