Page 1 of 2
is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:05 pm
by jeremybass
So working out the last problem i moved on to the next part and even though i just learned a few ways to show what is happening i hit a wall... sooo i put "WORKING INSERT INTO" and "WORKING DELETE FROM" in front of the cPath.
THE QUESTION?
well when i check an item it inserts just fine but when it's unchecked... if was checked, that item well not delete... so i know my code is not right for this but i don't know what path to take... it seems to me that else should be ____ may-be and.... is there and? Any ideas would be helpful... thanks
Here is the code unit try one:
Code: Select all
if ($picked = true) {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING INSERT INTO cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
}
break;
} else {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
}
break;}
}
}
try two:
Code: Select all
if ($picked = true) {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
} else {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
} tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL')); break;}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:07 pm
by John Cartwright
Hint:
= is the assignment operator
== is the comparison operator
=== is a type sensitive comparison operator
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:12 pm
by jeremybass
lol... ok i should have remebered that that was put of my problem yesterday... so i fixed it and only the only the top stays checked... was not expecting that... ideas? I'll see what i can pull out but i'm sure it's some stupid thing i keep over looking....
At least i'm moving forward... thanks for the help...

Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:13 pm
by John Cartwright
I don't understand what your trying to ask.
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:17 pm
by jeremybass
Well now the first item on the check list is checked and nothing else is regardless of what is ckecked...
this is what i'm thinking.... it's the "break;"
Code: Select all
if ($picked == true) {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
} else {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']),
'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
}
tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
break;}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:19 pm
by John Cartwright
So try removing the break if thats what you think. I'll help with what I can but the ball is in your court

Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:24 pm
by John Cartwright
Code: Select all
if ($picked == true) {
foreach ($_POST['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT
INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id)
VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ")
ON DUPLICATE KEY
UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ",
extra_fields_type_id=" .tep_db_input($key) . ";"
);
}
} else {
foreach ($_POST['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE
FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . "
WHERE extra_fields_type_id=" . tep_db_input($key) . "
and products_id=" . tep_db_input((int)$_GET['pID']) . ";"
);
}
}
tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
break;
}
}
After formatting your code so I can read it properly

, you can see there an extra two closing curly brackets, so I'm not sure exactly what you will be breaking out of.
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:27 pm
by jeremybass
well i am just not sure

i moved it to each loop then after the else statment... and the relsutes are all over the map... taking out the break; just deletes everthing... lol not full unexpected... just not sure how to move forward here...
edit
After formatting your
i can do that here?
don't i have to break out of each "foreach"?
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 1:49 pm
by jeremybass
EDIT___ thought.... if the if statement is looking a is $picked == true ... is it looking at the query stated in the form or at the post var? i was thinking it was the post but now im not sure... ideas?
the two closing curly brackets at the end are part of the great function that was working great before i add the if else statment:
Code: Select all
if ($picked == true) {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
} else {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
} tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
break;
in case it's relavent here is the whole function...
Code: Select all
if (tep_not_null($action)) {
switch ($action) {
case 'update':
$product_query = tep_db_query("select p.products_id, pd.language_id, pd.products_name from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_id = pd.products_id and p.products_id = '" . (int)$HTTP_GET_VARS['pID'] . "'");
$product = tep_db_fetch_array($product_query);
$pInfo = new objectInfo($product);
$languages = tep_get_languages();
for ($i=0, $n=sizeof($languages); $i<$n; $i++) {
if (isset($_GET['read']) && ($_GET['read'] == 'only')) {
$pInfo->products_name = tep_get_products_name($pInfo->products_id, $languages[$i]['id']);
$pInfo->products_description = tep_get_products_description($pInfo->products_id, $languages[$i]['id']);
$pInfo->products_url = tep_get_products_url($pInfo->products_id, $languages[$i]['id']);
} else {
$pInfo->products_name = tep_db_prepare_input($products_name[$languages[$i]['id']]);
$pInfo->products_description = tep_db_prepare_input($products_description[$languages[$i]['id']]);
$pInfo->products_url = tep_db_prepare_input($products_url[$languages[$i]['id']]);
}
}
if ($picked == true) {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
} else {
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
} tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'WORKING DELETE FROM cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
break;
}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 2:41 pm
by jeremybass
ok so moving ahead i can get it to half work... so QUESTION??
"elseif('CHECKED'==false)" valid? i know if close but ...

thanks for the help
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
if ('CHECKED'==true) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
} elseif('CHECKED'==false) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
} tep_redirect(tep_href_link(FILENAME_CATEGORIES, 'cPath=' . $cPath . '&pID=' . $pInfo->products_id . '&action=new_product', 'NONSSL'));
break;
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 3:13 pm
by jeremybass
ok i'v probly wrote this 50 times now... i'm so not sure... anyone got an idea on how where i should head? I know i'm close i'm just not sure now... here is the lastest version.... thanks
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
if ('CHECKED'== true) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
elseif ('CHECKED'!= true) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " and products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 4:19 pm
by jeremybass
May-be my question should be how write a true false statement for a a cheack box as it's being posted... try putting $HTTP_POST_VARS around checked no luck... i know i'm missing something fundamental here i just don't know what lol...
Last round still no luck... it seems like it only dose the insert part of the if statement... is there a way to test that? thanks again
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
if ("checked" == true) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
else {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
}
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 4:31 pm
by John Cartwright
if ("checked" == true) {
What exactly are you expecting this to do? You have a hardcoded string and your checking to see if it's true? It will always evaluate to true.
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 4:35 pm
by jeremybass
well i i was thinking the html input for a checkbox is 'checked' so i could use that to say if it is there then it'd insert other wise it'd delete... am i way off?
Re: is ELSE the right choice?
Posted: Sun Jan 20, 2008 5:10 pm
by jeremybass
ok so trying to address what you said this is the route i'v been trying... it's not working but i think it's a little closer...
Code: Select all
foreach ($HTTP_POST_VARS['mark'] as $key=>$val) {
$checked = "Checked: $key=>$val\n";
if ($checked == true) {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("INSERT INTO " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " (products_id, extra_fields_type_id) VALUES (" . tep_db_input((int)$_GET['pID']) . ", " .tep_db_input($key) . ") ON DUPLICATE KEY UPDATE products_id=" . tep_db_input((int)$_GET['pID']) . ", extra_fields_type_id=" .tep_db_input($key) . ";");
}
else {
$sql_data_array = array('products_id' => tep_db_prepare_input($val['products_id']), 'extra_fields_type_id' => 'extra_fields_type_id');
tep_db_query("DELETE FROM " . TABLE_PRODUCTS_TO_EXTRA_FIELDS . " WHERE extra_fields_type_id=" . tep_db_input($key) . " AND products_id=" . tep_db_input((int)$_GET['pID']) . ";");
}
}