my code is the following;
<select class="reg_field_field" id="user_address_state" name="user_address_state" tabindex="7">
<option value="AL" <?php if($state=='AL') echo 'selected';?>/>Alabama</option>
<option value="AK" <?php if($state=='AK') echo 'selected';?>/>Alaska</option>
<option value="AZ" <?php if($state=='AZ') echo 'selected';?>/>Arizona</option>
....
</select>
And the result is showing me instead the state name, it show "Notice: Undefined variable...".
I tried this in other server and worked, could be the php.ini configuration???
What can be on php.ini?
Thank you for any help
Ale
The error tells you the problem: $state is undefined. You need to examine your code to determine where $state should be defined and ensure that it is being set properly.
If you are attempting to save user input to the $state variable, look for a line like:
$state = $_POST['user_address_state'];
If it does not exist, create it prior to the lines you included in your post.
does $state have a default value? It has to have a value prior to checking to see if it matches against another.
Related
How to use variable inside $_POST as i have used the following code but it says undefined offset in second line. How can i solve it?
$p = $_GET['cii'];
$selectOption = $_POST[$p];
Below is the code:
echo'<form method ="POST">
<select name="'.$abc[3].'">
<option value="slow">slow</option>
<option value="medium">medium</option>
<option value="fast">fast</option>
</select>
<br>
Click to change
</form>';
$abc[] has some numbers and the select box is made with same name as the number.
Almost there:
$p = 'cii';
$selectOption = $_POST[$p];
you are accessing same page when you come first time you get undefined offset
So first check existence
if(isset($_GET['cii'])){
$p = $_GET['cii'];
$selectOption = $_POST[$p];
}
Also no need to add double && just use single & here
Click to change
Assuming variable $abc[3] gives you right value.
I am working on a project in which I have used JSON file to store data and used PHP to print it. But while comparing the value from $_POST, if it has spaces then comparison is not working otherwise there is no issue
This is what I am doing
$jsondata = file_get_contents("location-to-my-file-storage/".$_POST['mandi']."/".$_POST['crop'].".json");
$json = json_decode($jsondata, true);
foreach($json['crop'] as $data)
{
if ($data['name'] == $_POST['name'])
//This if statement is responsible for error
/* if $_POST['name'] = some value, then it's not working
but for $_POST['name'] = someValue, it is working properly
I have also tried if ($data['name'] == "$_POST['name'])"
but this is not working also
*/
{
/******
*do some printing here
*/
}
You can see a demo at http://divakarparashar.hol.es/innovation/en/user/farmer/price-calc.php
Select anything from two drop down list and click on available crops, it gives list for available crop. here comes the error, for a value with spaces like the first one 'Acorn Squash' nothing is happening, but for a value that has no space in it like 'Amarnath' every thing is working properly.
The same thing happened when I go for a mandi name or crop type with spaces in it, for the statement
$Jsonfile = file_get_contents("location-to-my-file-storage/".$_POST['nameMandi']."/".$_POST['cropType'].".json");
Where I am getting wrong ..??
please check your dropdown i.e <option> tags.
The value has cutted string in there thats why comparison is not working.
<select name="name" class="w3-btn w3-green w3-round w3-input">
<option name="crop" value="Acorn" squash="">Acorn Squash</option>
<option name="crop" value="Alfalfa" sprout="">Alfalfa Sprout</option>
<option name="crop" value="Amaranath">Amaranath</option>
I am sorry bad English. I have a select menu option value problem:
<select>
<option value=0>element1</option>
<option value=1>element2</option>
</select>
I am if select value="0" option and this post, it retuns the value with no problem. But, when I use value = 0 save mysql table, this value not 0 this return empty. This value saving column type integer? What is problem?
I am not using mysql_real_escape_string or any filter. If select value="1" option no problem, it is saving succesfully.
Thanks
I ran into this issue myself and what I found was that when posting option/select box values and reading them with PHP, when the 'value' of it was 0 it was acting like I did not post at all because I was checking to see anything had been posted like this:
if ($_POST['status']) {
// do stuff here
}
When in fact I needed to check it using isset(), because the way shown above returns false even if the value is 0. The example shown below checks to see if it really is set at all, even if the value is 0.
if (isset($_POST['status'])) {
// do stuff here
}
You did not show us your PHP code so I am only guessing this was also your problem.
you missed quotes (")
<select name="my_select">
<option value="0">element1</option>
<option value="1">element2</option>
</select>
<?php
$my_select_value = $_POST["my_select"];
echo $my_select_value;
?>
This one is a pain...no value is sent in the POST if it's a select and the value is 0....so if it's a POST and NOT sent you can assume the value was 0...
if($_POST){
if(isset($_POST['my_select'])){
//has a value, can assume it's 1 given the example
}else {
//posted, but value wasn't sent, can assume it's 0
}
}
So I have this problem, which I don't see how it's happening. Basically I have 2 arrays one of which has a list of apparatus and the other just has one apparatus that the user can operate. I want to have a dropdown list of all the apparatus avliable, but the default value that is selected is the one that they can operate (They can only operate one at a time) Here is the code, and I have an if statement to check if the user can operate it and selected = "selected" but that doesn't seem to be working (In firefox)... Any help would be great.
Thanks!
<?php
foreach ($apparatuslist as $apparatus):?>
<option value="<?php echo $apparatus['apparatus'];?>" <?php if ($driveron['apparatus'] == $apparatus['apparatus']){echo "SELECTED";} ?> ><?php echo substr($apparatus['apparatus'], 5); ?></option>
<?php endforeach;?>
You have it right in your question, but not in your code
<?php
foreach ($apparatuslist as $apparatus):?>
<option value="<?php echo $apparatus['apparatus'];?>" <?php if ($driveron['apparatus'] == $apparatus['apparatus']){echo "selected=\"selected\"";} ?> ><?php echo substr($apparatus['apparatus'], 5); ?></option>
<?php endforeach;?>
Should do the trick..
The code is correct. It's optional whether you write select="selected" or jus "selected" that doesn't effect firefox.The code is correct but not working means the problem in browser i guess. Either it is cache problem as newer version of firefox has cache problem or there may be other kind of problem in firefox. Please check in other computer's firefox.
correct syntax is: selected="selected" in OPTION tag
i have a problem with a drop-box that isn't populated correctly.
echo"<td>Selectati numarul de telefon:</td>
<td><select name='mobil'>
<option value='--'>---</option>";
while($apelantRow = mysql_fetch_assoc($apelantResult))
{
$apel=(string)$apelantRow['nrtel'];
echo "<option value='".$apel."'>$apel</option>";
}
echo"</select></td></tr>";
the sql query works fine. what i get is something like this:
<option value='2'>1</option>
<option value='2'>2</option>
I really don't know what to do. what is confusing me is that i have the same code, on an other page, with different variables and it works just fine.
please help.
thanks,
Sebastian
Why not
echo '<option value="'.$apel.'">'.$apel.'</option>';
?
EDIT : explicit cast doesn't required as variable is used in a string