Delete Button

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Delete Button

Post 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();
  ?>
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

What do you mean clicked on the server? You mean the achual server it self?
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

I deleted a piece of the code and im not sure what I deleted...
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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
}
?>
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

ok, it is being clicked but its not processing the delete... hmmmm
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Or press Ctrl+Z like crazy.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post 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
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post by superdezign »

Then find the delete function. What language is it in? PHP? JavaScript?
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post 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?
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Post 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.
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

But see my problem is I can't find whats wrong with the function, thats why i made this post haha
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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?
NuclearDoctor
Forum Newbie
Posts: 24
Joined: Thu Apr 26, 2007 9:34 am

Post by NuclearDoctor »

This sucks, I can't figure it out :(
Post Reply