piznac Posted August 16, 2007 Share Posted August 16, 2007 OK,.. I have this: <?php function del_art($path,$num){ echo "<script language=\"JavaScript\">var answer = confirm(\"Are you sure you want to delete this file?\");if (answer){alert(\"File will now be deleted\");set = 1;}else{set = 0;}</script>"; $set = "<script language=\"JavaScript\"> document.write(set) </script>"; echo $set; if($set != "0"){ //get just the file name $filename = explode("/", $path); //delete the file $do = unlink("/var/www/html/logo/$filename[4]"); //delete the file from db records $del_art_query = "DELETE FROM `or_logo` WHERE `path` = '$path' AND `num` = '$num'"; $del_art = mysql_query($del_art_query) or die ("del query error:" . mysql_error()); } ?> Now you will see that I threw some JS in there,.. this is for a confirm box. Now the $set variable is working. I echo it and it does change depending on which choice I make at confirm box. But no matter what $set is set to ,.. 0 or 1. It still preforms the rest of the function. Im a bit confused here,.. stupid mistake? Here is where Im calling it: <?php case "delart"; $path = mysql_real_escape_string(trim(stripslashes($_GET['path']))); $num = mysql_real_escape_string(trim(stripslashes($_GET['num']))); require_once("my path"); $this = new Confirm(); $this->del_art($path,$num); $this->dis_order($num); break; ?> Anyone have any ideas? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted August 16, 2007 Share Posted August 16, 2007 <?php function del_art($path,$num){ echo "<script language=\"JavaScript\">var answer = confirm(\"Are you sure you want to delete this file?\");if (answer){alert(\"File will now be deleted\");set = 1;}else{set = 0;}</script>"; $set = "<script language=\"JavaScript\"> document.write(set) </script>"; echo $set; if($set != "0"){ //get just the file name $filename = explode("/", $path); //delete the file $do = unlink("/var/www/html/logo/$filename[4]"); //delete the file from db records $del_art_query = "DELETE FROM `or_logo` WHERE `path` = '$path' AND `num` = '$num'"; $del_art = mysql_query($del_art_query) or die ("del query error:" . mysql_error()); } ?> Quote Link to comment Share on other sites More sharing options...
piznac Posted August 16, 2007 Author Share Posted August 16, 2007 ?? Quote Link to comment Share on other sites More sharing options...
jvrothjr Posted August 16, 2007 Share Posted August 16, 2007 opps sry did not paste the right one your are missing a } at the end $del_art = mysql_query($del_art_query) or die ("del query error:" . mysql_error()); } } ?> Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 16, 2007 Share Posted August 16, 2007 $set will never equal 0 or 1 $set equals <script language=\"JavaScript\"> document.write(set) </script> Quote Link to comment Share on other sites More sharing options...
piznac Posted August 16, 2007 Author Share Posted August 16, 2007 Yeah sorry I have the last } to close the function just didnt put it in here,.. my bad. And $set is equal to 1 or 0,.. as when I echo it it shows that it is. Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 16, 2007 Share Posted August 16, 2007 that is because you are telling php to write the javascript that then writes 0 or 1 Quote Link to comment Share on other sites More sharing options...
piznac Posted August 16, 2007 Author Share Posted August 16, 2007 OK,.. I see what you are saying,.. is there a way to get the variable to hold the value of the js var? Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 16, 2007 Share Posted August 16, 2007 The only way I can think of doing it atm is using ajax Quote Link to comment Share on other sites More sharing options...
piznac Posted August 16, 2007 Author Share Posted August 16, 2007 hmmm yeah that seems like a waste just for a confirm box,.. thanks for the help! Quote Link to comment Share on other sites More sharing options...
plutomed Posted August 16, 2007 Share Posted August 16, 2007 I'm sure there is a lot more people on here that is more helpful than I am! And I'm sure I have done something like this and done it another way but I can't remember soz. Quote Link to comment Share on other sites More sharing options...
piznac Posted August 16, 2007 Author Share Posted August 16, 2007 AHHHHH HA note: Im one of those guys who is hardheaded,..LOL But I figure out a way to do it,.. if I simply pass the php vars into the function,.. in a link it works: <a href=\"javascript:confirmation($nums,'$paths')\" border=\"0\"> <script type="text/javascript"> <!-- function confirmation(num,path) { var answer = confirm("Are you sure you want to delete this artwork?") if (answer){ alert("Entry Deleted") window.location = "confirm.php?action=delart&path="+path+"&num="+num; } else{ alert("No action taken") } } //--> </script> Thanks for the help guys!! Quote Link to comment 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.