Jump to content

I must be missing something


Tuk

Recommended Posts

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.