Page 1 of 1
send value 0 of drop down option
Posted: Thu Jul 11, 2013 7:26 pm
by ytyismail
here is part of my code
Code: Select all
<form action="dasskira.php" method='post'>
<td width="621">1) I found myself getting upset by quiet trivial things:</td>
<td width="45"><div align="center">
<select name="q1">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" />
</form>
initially the dropdown option show value 0..if the user does not choose from the option..then press submit button..the value 0 doesn't send to the next page (dasskira.php)..how can i make it work? i want value 0 send even the user didn't choose any option..
Re: send value 0 of drop down option
Posted: Thu Jul 11, 2013 8:18 pm
by Celauran
What do you mean it doesn't send? How are you testing for it?
Re: send value 0 of drop down option
Posted: Thu Jul 11, 2013 9:55 pm
by Christopher
It should work, so you need to check what is being received as Celauran recommended. I'd do the browser formatted:
Code: Select all
echo '<pre>' . print_r($_POST, 1) . '</pre>';
I assume that you are checking $_POST['q1'] for the value? And you are not using a check forgetting that 0 is also false.
You can be specific:
Code: Select all
<select name="q1">
<option value="0" selected="selected">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
Re: send value 0 of drop down option
Posted: Thu Jul 11, 2013 10:38 pm
by ytyismail
actually..i have 21 questions of dass questionaire..and this is part of the code that i checked the value post..sorry..i'm really new beginners... im try to make the code simple as i can understand it..maybe these code wrong...but i didn't know why..i have test it..it worked...but if user send submit button without choose any option..it just display blank page..
dasskira.php
Code: Select all
if( $_POST['q3'] || $_POST['q5'] || $_POST['q10'] || $_POST['q13'] || $_POST['q16'] || $_POST['q17'] || $_POST['q21'] ) {
echo "selected q3: ".$_POST['q3']. "<br />";
echo "selected q5: ".$_POST['q5']. "<br />";
echo "selected q10: ".$_POST['q10']. "<br />";
echo "selected q13: ".$_POST['q13']. "<br />";
echo "selected q16: ".$_POST['q16']. "<br />";
echo "selected q17: ".$_POST['q17']. "<br />";
echo "selected q21: ".$_POST['q21']. "<br />". "<br />";
$sum = $_POST['q3'] + $_POST['q5'] + $_POST['q10'] + $_POST['q13']+ $_POST['q16'] + $_POST['q17'] + $_POST['q21'];
echo "Score for depression : ".$sum. "<br />". "<br />";
if ($sum <= 4) {
echo "Normal depression". "<br />" ."<br />"."<br />";
}
else if($sum >= 5 && $sum <= 6) {
echo "Mild depression". "<br />"."<br />"."<br />";
}
else if($sum >= 7 && $sum <= 10) {
echo "Moderate depression". "<br />"."<br />"."<br />";
}
else if($sum >= 11 && $sum <= 13) {
echo "Severe depression". "<br />"."<br />"."<br />";
}
else if($sum >= 14) {
echo "Extremely Severe depression". "<br />"."<br />" ."<br />";
}
}
Re: send value 0 of drop down option
Posted: Fri Jul 12, 2013 7:53 am
by AbraCadaver
Nowhere in this code are you checking or using $_POST['q1']