amylou Posted August 24, 2007 Share Posted August 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/ Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 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.." Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333552 Share on other sites More sharing options...
pocobueno1388 Posted August 24, 2007 Share Posted August 24, 2007 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 =] Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333554 Share on other sites More sharing options...
amylou Posted August 24, 2007 Author Share Posted August 24, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333556 Share on other sites More sharing options...
micmania1 Posted August 24, 2007 Share Posted August 24, 2007 <?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 '*'. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333559 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333561 Share on other sites More sharing options...
amylou Posted August 24, 2007 Author Share Posted August 24, 2007 micmania1 i tried that it also does not work, when i click the delete link all i get is a white page so i ran it again and the date that i tried to delete was still there Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333563 Share on other sites More sharing options...
pocobueno1388 Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333566 Share on other sites More sharing options...
micmania1 Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333567 Share on other sites More sharing options...
lemmin Posted August 24, 2007 Share Posted August 24, 2007 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. Also, you didn't answer, is the requestId field a string data type? Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333569 Share on other sites More sharing options...
micmania1 Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333574 Share on other sites More sharing options...
amylou Posted August 24, 2007 Author Share Posted August 24, 2007 requestId is an auto incremented number in the database to use as primary key in database. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333575 Share on other sites More sharing options...
micmania1 Posted August 24, 2007 Share Posted August 24, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333580 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333584 Share on other sites More sharing options...
pocobueno1388 Posted August 25, 2007 Share Posted August 25, 2007 Did you try using my code as reference? Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333587 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 yes i did and i still got the blank screen Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333597 Share on other sites More sharing options...
micmania1 Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333602 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333606 Share on other sites More sharing options...
micmania1 Posted August 25, 2007 Share Posted August 25, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333610 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333615 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 i have all the validation stuff turned on and the only errors i am getting has to do with linking of my css files Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333619 Share on other sites More sharing options...
amylou Posted August 25, 2007 Author Share Posted August 25, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-333641 Share on other sites More sharing options...
amylou Posted August 28, 2007 Author Share Posted August 28, 2007 my problem now is that it will tell the user that it has been deleted but does not delete from database. any ideas Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-336561 Share on other sites More sharing options...
pocobueno1388 Posted August 28, 2007 Share Posted August 28, 2007 echo your query out and see what it prints...there is probably a variable with no value in it. Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-336750 Share on other sites More sharing options...
amylou Posted August 29, 2007 Author Share Posted August 29, 2007 when i echoed out the query the following it printed the following DELETE FROM timeoff where last =" AND first=" and when i echoed out the result of query i get the number 1 Quote Link to comment https://forums.phpfreaks.com/topic/66586-solved-problem-deleting/#findComment-336842 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.