send value 0 of drop down option

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
ytyismail
Forum Newbie
Posts: 2
Joined: Thu Jul 11, 2013 7:09 pm

send value 0 of drop down option

Post 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..
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: send value 0 of drop down option

Post by Celauran »

What do you mean it doesn't send? How are you testing for it?

Code: Select all

print_r($_POST);
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: send value 0 of drop down option

Post 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>
(#10850)
User avatar
ytyismail
Forum Newbie
Posts: 2
Joined: Thu Jul 11, 2013 7:09 pm

Re: send value 0 of drop down option

Post 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 />";

}

  
}
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: send value 0 of drop down option

Post by AbraCadaver »

Nowhere in this code are you checking or using $_POST['q1']
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Post Reply