Page 1 of 2

Delete Button

Posted: Tue May 01, 2007 4:35 pm
by NuclearDoctor
I had help from someone on the site, he helped me make a delete button and I started changing some of the code around and removing some things, and now the buttons arn't working right and I can't figure out why and I need this in about 90 minuets... can anyone help me out if they see anything that would cause these buttons not to delete the entries when delete is clicked?

Code: Select all

<html>
<head>
<title>
<?
include "admin_panel_title.php";?>
</title>
</head>
<body bgcolor="#000000" text="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0" link="#FF3333" vlink="#CC0000" alink="#CC0000">
<center>
<img src="/newadmin/Administration_Panel_Banner.png"><br>
<h3>Remove a Person from a Duty Crew</h3>

<?

//include "http://delranfire.org/members/connect.phtml";
include "connect.phtml";

$db="delranfire_org";
$query="select * from dutycrews order by name desc";

//echo $query;

if(isset($_GET['id']) && isset($_GET['action'])) {  
	$tempResult = mysql_db_query($db, "SELECT * FROM dutycrews WHERE id=" . mysql_escape_string($_GET['id']), $connection);
	if(mysql_num_rows($tempResult) > 0) {  
		if($_GET['action'] == "del") {  
			mysql_db_query($db, "DELETE FROM dutycrews WHERE id=" . mysql_escape_string($_GET['id']), $connection);
		}
	}
}

$rows=mysql_db_query($db,$query,$connection) or die("Error in query:$query. " .mysql_error());



?>

<script language=javascript>

function deleteEntryOld(entry)
{

	var moo = '\"DELETE FROM dutycrews WHERE id=\'' + entry + '\'\"';

	<?
	$qu = "?><script language=javascript>document.write(moo)</script><?";
	
	mysql_query($qu);
	?>

	var sURL = unescape(window.location.pathname);
	window.location.href = sURL;
	
}

</script> </font>

                              <table width="70%" border="0" cellspacing="0" cellpadding="0" align=center>

 <tr>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Name</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Station</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Date</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Start</font></b></td>

                                <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Finish</font></b></td>
					
					  <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Position</font></b></td>

					  <td> <b><font face="Arial, Helvetica, sans-serif" size="1">Truck</font></b></td>

                                </font></td></tr>

                                <tr><td colspan=8><hr></td></tr>

                                <?

while($row=mysql_fetch_array($rows)){

?>



                                <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?

                                $name="$row[name]";



                                echo $row["name"];?>



                                </font></td>

                                 <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["station"];?>

                                </font></td>

                                <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["dat"];?>

                                </font>

					  <font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["dat_day"];?>

                                </font></td>

                                <td><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["fr"];?>

                                </font></td>

                                <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["toa"];?>

                                </font></td>

					  <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["position"];?>

                                </font></td>

					  <td ><font face="Arial, Helvetica, sans-serif" size="1" color="#FFFFFF">

                                <?echo $row["truck"];?>

                                <td colspan=8 align=right><input type=button value="Delete" onClick="deleteEntry('<?echo $row["id"];?>')"> </input></td></tr>

                                </font></td></tr>


                                 <tr><td colspan=8><hr></td></tr>

                                <?}?>
				

                              </table>

                              </td>

                          </tr>

                        </table>

                      </td>

                    </tr>

                  </table>

                </td>

              </tr>

            </table>
<center><a href="/newadmin/">Back to Administration Panel</a></center>
</body></html>
  <?
  mysql_close();
  ?>

Posted: Tue May 01, 2007 4:45 pm
by RobertGonzalez
Man, that looks like you are trying to mix Javascript, PHP and HTML all in the same routine. Check to see if the delete button is clicked on the server, and if that button is clicked, process the delete.

Posted: Tue May 01, 2007 5:07 pm
by NuclearDoctor
What do you mean clicked on the server? You mean the achual server it self?

Posted: Tue May 01, 2007 5:12 pm
by NuclearDoctor
I deleted a piece of the code and im not sure what I deleted...

Posted: Tue May 01, 2007 5:12 pm
by RobertGonzalez
No, I mean use PHP (on the server) to check if the button was clicked.

Code: Select all

<?php
if (isset($_POST['deleteButton'])) {
  // yadda yadda
}
?>

Posted: Tue May 01, 2007 5:24 pm
by NuclearDoctor
ok, it is being clicked but its not processing the delete... hmmmm

Posted: Tue May 01, 2007 5:24 pm
by superdezign
Or press Ctrl+Z like crazy.

Posted: Tue May 01, 2007 5:25 pm
by superdezign
NuclearDoctor wrote:ok, it is being clicked but its not processing the delete... hmmmm
Does your if(isset(whatever)) DO something after it's being clicked? I'm sure if it used to delete, there's a function around there somewhere that does it.

Posted: Tue May 01, 2007 5:30 pm
by NuclearDoctor
i wish i could do ctrl + z, but it doens't work because i already saved it and left it =/ i tryed that haha

all i know is there was one piece of code that was in there before and i deleted it by accident

Posted: Tue May 01, 2007 5:31 pm
by superdezign
Then find the delete function. What language is it in? PHP? JavaScript?

Posted: Tue May 01, 2007 5:44 pm
by NuclearDoctor
php and i think a little java

Does anyone see anything that can be causing the delete option to not delete an entry?

Posted: Tue May 01, 2007 5:55 pm
by superdezign
The only way is if your delete button isn't calling a delete function. Buttons aren't magic.
Find the function, and make it work.

Posted: Tue May 01, 2007 5:57 pm
by NuclearDoctor
But see my problem is I can't find whats wrong with the function, thats why i made this post haha

Posted: Tue May 01, 2007 6:03 pm
by RobertGonzalez
Look how deep your delete check is:

Code: Select all

<?php
if(isset($_GET['id']) && isset($_GET['action'])) { 
        $tempResult = mysql_db_query($db, "SELECT * FROM dutycrews WHERE id=" . mysql_escape_string($_GET['id']), $connection);
        if(mysql_num_rows($tempResult) > 0) { 
                if($_GET['action'] == "del") { 
                        mysql_db_query($db, "DELETE FROM dutycrews WHERE id=" . mysql_escape_string($_GET['id']), $connection);
                }
        }
}
?>
In order for the query string var 'del' to be triggered $_GET['id'] has to be set and $_GET['action'] has to be set, then the query needs to run and the result set needs to be more than 0 rows long, then $_GET['action'] needs to be 'del'. That is an awful lot of conditionals. Are they are firing?

Posted: Tue May 01, 2007 6:47 pm
by NuclearDoctor
This sucks, I can't figure it out :(