Tuk Posted January 31, 2012 Share Posted January 31, 2012 To make a long story short, I have a series of forms, where certain options are visible depending on what the user selected on the previous form. The final form processing is where I'm having issues. I have the following for each option, to check if that option was selected (this is all somewhat pared down for clarity): if (isset($_POST['option1']) && $_POST['option1'] > 0){ $option1 = mysql_real_escape_string($_POST['option1']); $query1 = "DELETE FROM table WHERE itemid = '$option1'"; } I have that basic thing for each of the options, where it assigns a deletion query based on each individual option. Later in my code, I have the following, which again checks if each option was selected (it's restated because it's after several error checks) then is supposed to run the query that was assigned in the previous part: if ($_POST['option1'] > 0){ mysql_query($query1); } if ($_POST['option2'] > 0){ mysql_query($query2); } if ($_POST['option3'] > 0){ mysql_query($query3); } (etc, for all the options) My problem is that the queries are not executing and I can't see any reason why not. Query #1 is working... it executes the deletion query and all is well, but if I try to select any options other than #1, the query doesn't execute. I tried echoing the queries within the second if statements above (where it runs the queries) and it's echoing them fine (and they look normal), so I know it's able to run the queries, it just isn't... Am I blind? lol. I must be missing something obvious because this is driving me crazy. Thank you in advance. Please let me know if you need more info. Quote Link to comment https://forums.phpfreaks.com/topic/256124-i-must-be-missing-something/ Share on other sites More sharing options...
Pikachu2000 Posted January 31, 2012 Share Posted January 31, 2012 You may want to post the actual code. There has to be a better/more efficient way to handle this anyhow. Quote Link to comment https://forums.phpfreaks.com/topic/256124-i-must-be-missing-something/#findComment-1312991 Share on other sites More sharing options...
Tuk Posted January 31, 2012 Author Share Posted January 31, 2012 Alright, here's the basics of it... I thought about using implode() to only delete the ones the user selected, but I couldn't make it work properly so I went the long route. if (isset($_POST['submitprocesstrade'])){ $tradingfor = mysql_real_escape_string($_POST['retaindbid']); $getitem = @mysql_query("SELECT itemname, originaluses, itemtype FROM itemdb WHERE dbid = '$tradingfor'"); $itemtrade = @mysql_fetch_array($getitem); $failflag = 0; $query1 = ""; $query2 = ""; $query3 = ""; $query4 = ""; $query5 = ""; $query6 = ""; $query7 = ""; $query8 = ""; $query9 = ""; $query10 = ""; $query11 = ""; $query12 = ""; if (isset($_POST['commonyarn1']) && $_POST['commonyarn1'] > 0 && is_numeric($_POST['commonyarn1'])){ $commonany = mysql_real_escape_string($_POST['commonyarn1']); $query1 = "DELETE FROM yarns WHERE yarnid = '$commonany'"; }elseif (isset($_POST['commonyarn1']) && $_POST['commonyarn1'] == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['commonyarn2']) && $_POST['commonyarn2'] > 0 && is_numeric($_POST['commonyarn2'])){ $commonsock = mysql_real_escape_string($_POST['commonyarn2']); $query2 = "DELETE FROM yarns WHERE yarnid = '$commonsock'"; }elseif (isset($_POST['commonyarn2']) && $_POST['commonyarn2'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['commonyarn3']) && $_POST['commonyarn3'] > 0 && is_numeric($_POST['commonyarn3'])){ $commonsport = mysql_real_escape_string($_POST['commonyarn3']); $query3 = "DELETE FROM yarns WHERE yarnid = '$commonsport'"; }elseif (isset($_POST['commonyarn3']) && $_POST['commonyarn3'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['commonyarn4']) && $_POST['commonyarn4'] > 0 && is_numeric($_POST['commonyarn4'])){ $commonbulky = mysql_real_escape_string($_POST['commonyarn4']); $query4 = "DELETE FROM yarns WHERE yarnid = '$commonbulky'"; }elseif (isset($_POST['commonyarn4']) && $_POST['commonyarn4'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['uncommonyarn1']) && $_POST['uncommonyarn1'] > 0 && is_numeric($_POST['uncommonyarn1'])){ $uncommonany = mysql_real_escape_string($_POST['uncommonyarn1']); $query5 = "DELETE FROM yarns WHERE yarnid = '$uncommonany'"; }elseif (isset($_POST['uncommonyarn1']) && $_POST['uncommonyarn1'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['uncommonyarn2']) && $_POST['uncommonyarn2'] > 0 && is_numeric($_POST['uncommonyarn2'])){ $uncommonsock = mysql_real_escape_string($_POST['uncommonyarn2']); $query6 = "DELETE FROM yarns WHERE yarnid = '$uncommonsock'"; }elseif (isset($_POST['uncommonyarn2']) && $_POST['uncommonyarn2'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['uncommonyarn3']) && $_POST['uncommonyarn3'] > 0 && is_numeric($_POST['uncommonyarn3'])){ $uncommonsport = mysql_real_escape_string($_POST['uncommonyarn3']); $query7 = "DELETE FROM yarns WHERE yarnid = '$uncommonsport'"; }elseif (isset($_POST['uncommonyarn3']) && $_POST['uncommonyarn3'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['uncommonyarn4']) && $_POST['uncommonyarn4'] > 0 && is_numeric($_POST['uncommonyarn4'])){ $uncommonbulky = mysql_real_escape_string($_POST['uncommonyarn4']); $query8 = "DELETE FROM yarns WHERE yarnid = '$uncommonbulky'"; }elseif (isset($_POST['uncommonyarn4']) && $_POST['uncommonyarn4'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['rareyarn1']) && $_POST['rareyarn1'] > 0 && is_numeric($_POST['rareyarn1'])){ $rareany = mysql_real_escape_string($_POST['rareyarn1']); $query9 = "DELETE FROM yarns WHERE yarnid = '$rareany'"; }elseif (isset($_POST['rareyarn1']) && $_POST['rareyarn1'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['rareyarn2']) && $_POST['rareyarn2'] > 0 && is_numeric($_POST['rareyarn2'])){ $raresock = mysql_real_escape_string($_POST['rareyarn2']); $query10 = "DELETE FROM yarns WHERE yarnid = '$raresock'"; }elseif (isset($_POST['rareyarn2']) && $_POST['rareyarn2'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['rareyarn3']) && $_POST['rareyarn3'] > 0 && is_numeric($_POST['rareyarn3'])){ $raresport = mysql_real_escape_string($_POST['rareyarn3']); $query11 = "DELETE FROM yarns WHERE yarnid = '$raresport'"; }elseif (isset($_POST['rareyarn2']) && $_POST['rareyarn2'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if (isset($_POST['rareyarn4']) && $_POST['rareyarn4'] > 0 && is_numeric($_POST['rareyarn4'])){ $rarebulky = mysql_real_escape_string($_POST['rareyarn4']); $query12 = "DELETE FROM yarns WHERE yarnid = '$rarebulky'"; }elseif (isset($_POST['rareyarn4']) && $_POST['rareyarn4'] == 0 && $failflag == 0){ $failflag = 1; errorbox("You don't have all the yarn required to make this trade!"); } if ($failflag == 0){ //no fail if ($_POST['commonyarn1'] > 0){ @mysql_query($query1); } if ($_POST['commonyarn2'] > 0){ @mysql_query($query2); } if ($_POST['commonyarn3'] > 0){ @mysql_query($query3); } if ($_POST['commonyarn4'] > 0){ @mysql_query($query4); } if ($_POST['uncommonyarn1'] > 0){ @mysql_query($query5); } if ($_POST['uncommonyarn2'] > 0){ @mysql_query($query6); } if ($_POST['uncommonyarn3'] > 0){ @mysql_query($query7); } if ($_POST['uncommonyarn4'] > 0){ @mysql_query($query8); } if ($_POST['rareyarn1'] > 0){ @mysql_query($query9); } if ($_POST['rareyarn2'] > 0){ @mysql_query($query10); } if ($_POST['rareyarn3'] > 0){ @mysql_query($query11); } if ($_POST['rareyarn4'] > 0){ @mysql_query($query12); } successbox("You've traded in some yarn!"); } include("./footer.php"); die(); } So as you can see, all the queries are executed in the same manner, yet for some reason only the first option works. Thanks for looking over it. -Tuk Quote Link to comment https://forums.phpfreaks.com/topic/256124-i-must-be-missing-something/#findComment-1312999 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.