Shadowing Posted December 11, 2011 Share Posted December 11, 2011 Im having trouble with this wondering if someone could help me out please if (isset($_POST['escape'])) { || if (isset($_POST['suicide'])) { its giving me a error on the || im writing it so that one or the other has to happend. is this the correct way to use this? Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/ Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 maybe its suppose to be more closer to something like this if (isset($_POST['escape']) || (isset($_POST['suicide'])) { Edit: nevermind i got it to work forgot to add the other ) so its (isset($_POST['escape']) || (isset($_POST['suicide']))) { Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296891 Share on other sites More sharing options...
Winstons Posted December 11, 2011 Share Posted December 11, 2011 You must write as if(isset($_POST['escape']) || isset($_POST['suicide'])){ // Do something } else { // Else do something } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296893 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 I'm trying to let people delete their account but its not working if (isset($_POST['escape']) || (isset($_POST['suicide']))) { }else{ if(empty($_POST['agree'])){ echo "You need to check the box"; }else{ mysql_query("DELETE FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id']))."'"; } } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296900 Share on other sites More sharing options...
dzelenika Posted December 11, 2011 Share Posted December 11, 2011 you cannot have two else blocks Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296901 Share on other sites More sharing options...
Winstons Posted December 11, 2011 Share Posted December 11, 2011 Why empty firs body of 'if' ??? if (isset($_POST['escape']) || (isset($_POST['suicide']))) { // Why here is nothing wrote ??? } else { if(empty($_POST['agree'])){ echo "You need to check the box"; }else{ mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']); } } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296902 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 its a check box they have to check before the next else happends why cant i have two else blocks like that? Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296903 Share on other sites More sharing options...
Winstons Posted December 11, 2011 Share Posted December 11, 2011 Shadowing Why it is empty ? Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296905 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 Forgot to say thanks for reading my post and helping me guys I get a error with using your code on mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']); im trying to get it to read saying if one of the two buttons are clicked and agree isnt empty then account will get deleted where the id matches the id session. thats a good point you made haha i need to change it to if(!empty($_POST['agree'])){ Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296909 Share on other sites More sharing options...
dzelenika Posted December 11, 2011 Share Posted December 11, 2011 if (isset($_POST['escape']) || (isset($_POST['suicide']))) { if(empty($_POST['agree'])){ echo "You need to check the box"; }else{ mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']); } } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296913 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 oh i guess it needs to read more like this. I took out the or for testing reasons this still doesnt work though hmm if (isset($_POST['escape'])) { if(empty($_POST['agree'])){ echo "You need to check the box"; } else { mysql_query("DELETE FROM users WHERE id='".mysql_real_escape_string($_SESSION['user_id']))."'"; } } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296914 Share on other sites More sharing options...
dzelenika Posted December 11, 2011 Share Posted December 11, 2011 i think it is better to use if(!isset(... instead if(empty(... Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296918 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 k i changed it to isset. just curious why you say it is beter cause ive been using empty alot maybe i should stop still getting a error on mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']); Parse error: syntax error, unexpected ';' in C:\Software\XAMPP\xampp\htdocs\stargate\delete_account.php on line 70 if (isset($_POST['escape'])) { if(!isset($_POST['agree'])){ echo "You need to check the box"; } else { mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']); } } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296920 Share on other sites More sharing options...
The Little Guy Posted December 11, 2011 Share Posted December 11, 2011 I am not usually a fan of deleting data from a table, and I don't recommend doing it (but it also depends on what the table is for). You should have a toggle field, set it to "1" for an active user, or "0" for an inactive/deleted user. <?php if (isset($_POST['escape']) || (isset($_POST['suicide']))) { // Why here is nothing wrote ??? }elseif(empty($_POST['agree'])){ echo "You need to check the box"; }else{ mysql_query("update users set is_active = 0 where id = ".(int)$_SESSION['user_id']); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296921 Share on other sites More sharing options...
dzelenika Posted December 11, 2011 Share Posted December 11, 2011 you omitted a brace at the end mysql_query("DELETE FROM `users` WHERE `id`= ".(int)($_SESSION['user_id']) ) ; Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296922 Share on other sites More sharing options...
Winstons Posted December 11, 2011 Share Posted December 11, 2011 empty - return true if you pass it 0. Therefore better use 'isset' elseif(!isset($_POST['agree'])){ echo "You need to check the box"; } Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296923 Share on other sites More sharing options...
Shadowing Posted December 11, 2011 Author Share Posted December 11, 2011 Thanks guys so much! It all works now Yah im creating a way for them to reset their account too. that toggle switch idea is a good idea. I was just going to use a another data base property for that but i may do that now instead only on my 2nd week learning php lol. its pretty awesome Quote Link to comment https://forums.phpfreaks.com/topic/252948-proper-way-of-using-or-with-two-if-commands/#findComment-1296925 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.