co.ador Posted January 23, 2010 Share Posted January 23, 2010 I want to set $offerings to $_REQUEST only if it is set. '&offerings=' .$_REQUEST['frmSearch']['offerings'][0]. "' I want you guys to check if the script below is correct. <?php isset($_REQUEST['frmSearch']['offerings'][0]?'&offerings=' .$_REQUEST['frmSearch']['offerings'][0]. ':'';?> Some how this index array is throwing an undefined index message when it is not set in the form. So I want that when being retrieve, only retrieve if it is set in the form to avoid this undefined index message. THank you. Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/ Share on other sites More sharing options...
oni-kun Posted January 23, 2010 Share Posted January 23, 2010 Do not use $_REQUEST. Only POST/GET, You're setting yourself up for injection. EDIT: You're using shorthand as well? Where did you learn your PHP from? If you used longhand (as preferred, and more efficient) you will obviously see the very simple solution. I'm against sloppy coding, As you can see it just brings problems. Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000336 Share on other sites More sharing options...
co.ador Posted January 23, 2010 Author Share Posted January 23, 2010 <?php '&food_types= ' . $_POST['frmSearch']['food_types'][0]. if( isset($_POST['frmSearch']['offerings'][0])){'&offerings=' .$_POST['frmSearch']['offerings'][0]. } else{''}. "'?> If you say I am setting myself up for injection no way... I took out the $_REQUEST for POST. I have also change to if and else statement since it is more effective. But still that set up above is throwing a big parse error message. Help! Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000337 Share on other sites More sharing options...
oni-kun Posted January 23, 2010 Share Posted January 23, 2010 <?php '&food_types= ' . $_POST['frmSearch']['food_types'][0]. if( isset($_POST['frmSearch']['offerings'][0])){'&offerings=' .$_POST['frmSearch']['offerings'][0]. } else{''}. "'?> If you say I am setting myself up for injection no way... I took out the $_REQUEST for POST. I have also change to if and else statement since it is more effective. But still that set up above is throwing a big parse error message. Help! The $_REQUEST variable is a combination of key and values of $_POST, $_GET and $_COOKIE variables. This is a 'superglobal', or automatic global, variable. This means that you do not know where the value is coming from, can be changed in $_GET itself, can be set in cookie, allow hijacking sessions and data retrieval. Why not just turn register globals on as well and call it a day? <?php if (!isset($_POST['form']['offerings'])) { die('Offerings form not set'); } else { echo '&food_types= ' . $_POST['frmSearch']['food_types'][0] . $_POST['frmSearch']['offerings'][0]; } ?> But what are you trying to do? And please, stop shoving code onto one line. Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000338 Share on other sites More sharing options...
co.ador Posted January 23, 2010 Author Share Posted January 23, 2010 The thing is that some how this offering input check boxes are not even present when passing from the form to page2.php when I var_dump even when no input in none of the fields the offering field won't appear inside the var_dump while all of the others input fields will appear empty but they pass to page2.php at least. offering as I said will only pass if it is checked or set. So when there is not input in the offering input field then when the form submits to page2.php then page2.php will trow a undefined index offerings because it is not passing, and it won't display the undefined index if the input checked box offering input field is set. That's why I am trying to set this test where it will pass the offering input field as empty at least if it is not set and if it is set then it will $_POST['frmSearch']['offerings'][0]. You have included food_types as well. But the thing is that food_types index is passing empty at least. I don't quite understand why food_types which has the same characteristics as offerings two arrays one passes as empty when is not set and the other if it is not set it won't pass at all, not empty no nothing. so that's what I am trying to do. Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000339 Share on other sites More sharing options...
co.ador Posted January 23, 2010 Author Share Posted January 23, 2010 <?php echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage&name=". $_POST['name']. '&zipcode=' . $_POST['zipcode'] .'&state=' . $_POST['state'] . '&food_types= ' . $_POST['frmSearch']['food_types'][0]. if (!isset($_POST['frmSearch']['offerings'])) {echo ""; } else { echo '&offerings= ' . $_POST['frmSearch']['offerings'][0] .;} "'>></a> ";?> The script above has a parse error don't see it. if you can see the if and else statement at the end I have just include the offering index inside since food_type is passing ok. I have set it up to echo empty if it is no set else echo {blabla} But there is a parse error help!! Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000340 Share on other sites More sharing options...
sasa Posted January 23, 2010 Share Posted January 23, 2010 <?php echo " <a href='{$_SERVER['PHP_SELF']}?currentpage={$nextpage}&name=", $_POST['name'], '&zipcode=' , $_POST['zipcode'] , '&state=' , $_POST['state'] , '&food_types= ' , $_POST['frmSearch']['food_types'][0], !isset($_POST['frmSearch']['offerings']) ? "" : ('&offerings= ' . $_POST['frmSearch']['offerings'][0]) . "'>></a> "; ?> Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000355 Share on other sites More sharing options...
co.ador Posted January 23, 2010 Author Share Posted January 23, 2010 Thank you sasa. I have to say the code above won't display in the browser the character > in between the two <a> tags or linking tags. It looks like [1] 2 3 4, but it won't display the > at the end of the pagination like. [1] 2 3 4 > >> Thank you. Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000501 Share on other sites More sharing options...
wildteen88 Posted January 23, 2010 Share Posted January 23, 2010 Use > instead of > and < instead of < Quote Link to comment https://forums.phpfreaks.com/topic/189516-need-some-help-setting-a-variable/#findComment-1000507 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.