Jump to content

Need some help setting a variable


co.ador

Recommended Posts

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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!

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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!!

Link to comment
Share on other sites

<?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> ";
?> 

Link to comment
Share on other sites

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.

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.