Eugene Posted April 14, 2006 Share Posted April 14, 2006 [code]if($qqq == $uuu) { echo "<tr> <td> </td> <td valign=\"768\"> <div class=\"tableborder\"> <div class=\"maintitle\">Confirmation</div> <form method=\"post\"> Are you sure you want to delete: <b>$ttt</b>?<br><br> <input type=\"submit\" name=\"iii\" value=\"Delete\"> </form>"; if($_POST['iii']) { echo "Hi"; } if(!$_POST['iii']) { echo "Bye"; } } if($qqq != $uuu) { echo "<tr> <td> </td> <td valign=\"768\"> <div class=\"tableborder\"> <div class=\"maintitle\">Error</div> We're Sorry, but we cannot find that users ID in our Database </div> </td>"; }[/code]There's the code. Everything looks right. Right?Anyway when I go to the page, it echos the "Bye" Next to the delete button which the name is iii and I didn't even submit it! Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/ Share on other sites More sharing options...
AV1611 Posted April 14, 2006 Share Posted April 14, 2006 I believe the problem is with this snippet: if($_POST['iii']) { echo "Hi"; } if(!$_POST['iii']) { echo "Bye";the second if will always be true the way it is written, I think...either way, do it like this, Bye will only display if $_POST['iii'] doesn't exist that way... if(isset($_POST['iii'])) { echo "Hi"; } else { echo "Bye";} Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26962 Share on other sites More sharing options...
Eugene Posted April 14, 2006 Author Share Posted April 14, 2006 [a href=\"http://imageshack.us\" target=\"_blank\"][img src=\"http://img143.imageshack.us/img143/7199/conf2zf.png\" border=\"0\" alt=\"IPB Image\" /][/a]Still :( Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26967 Share on other sites More sharing options...
wildteen88 Posted April 14, 2006 Share Posted April 14, 2006 What are you trying to do? Becuase that is the correct result your getting with the following codet:[code] if(isset($_POST['iii'])) {echo "Hi";}else { echo "Bye";}[/code]Because what the above code does is check whether $_POST['iii'] is set, if it is it'll echo out [b]Hi[/b], otherwise if $_POST['iii'] is not set it'll echo [b]Bye[/b]. This code will run with or without the Delete button being clicked.So what are you trying to do? Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26977 Share on other sites More sharing options...
Eugene Posted April 14, 2006 Author Share Posted April 14, 2006 WEll the Hi, is supposed to be the code that deleted the specified user. Bye is just a test to see if the submit button is working, obviously not. Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26983 Share on other sites More sharing options...
wildteen88 Posted April 14, 2006 Share Posted April 14, 2006 So you want to disply Hi instead of Bye? I dont get what you are trying to do. PHP is not like Javascript you know where you click say a link and the text in the certain div changes to something else. PHP is completly different the code will only run when you request a page, ie when you submit a form or click a link.Can you please explain in more detail about what you are attempting to do when you click the delete button. As currently your code is working correctly as when you request a page nothing will be set in the $_POST variable until you send _POST data to one of your pages, which the $_POSt['iii'] variable will be set when you click the delete button and your form submits, untill your form submits nothing will evaluate to true in the current you are using to show Hi or Bye.Take this example:[code]<?phpif(isset($_GET['iii'])){ echo "You have clicked the link! (Hi)";}else{ echo "Oh, You havn't clicked the link. (Bye)";}?><p><a href="?iii=Delete">Click this link</a></p>[/code]That code is the same as what you have got currently but I'm using a link and submitting the data over the URL whihc is the GET method. That is currently way your script is doing. The message [i]Oh, You havn't clicked the link. (Bye)[/i] wont change until you click the link. Quote Link to comment https://forums.phpfreaks.com/topic/7406-why-does-this-happen/#findComment-26990 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.