with a form being POSTed to another page (or itself) $_POST['checkbox_name'] will give the value IF you use <input type="checkbox" name="checkbox_name" value="1" />
if you submit your form with method="get" then $_GET['checkbox_name'] will give the value.
there is also $_REQUEST['checkbox_name'] which is a merging of $_GET and $_POST BUT I suggest you shy away from using this method, as its easier to debug when you know where stuff is coming from
BUT checkboxes DO NOT get submitted if you dont tick them.
My personal workaround to force the value being submitted is this:-
<input type="hidden" name="checkbox_name" value="0" />
<input type="checkbox" name="checkbox_name" value="1" />
When the webpage goes through the form to collate the values, IF the checkbox is ticked, it will overwrite the 0 value with 1. IF not then 0 will be submitted.
Hope this covers everything for you.
Suppose you have checkbox in HTML from and and you are calling that checkbox by name in php , In that case in you don't check and hit submit , You will get Undefined parameter 'name_of _checkbox' As Error.
The value associated with the checkbox's name, if it is checked, is the value attribute on the corresponding HTML input element.
using the post command.$_POST['checkboxname'];
Below is a simple example of how you could return a value in a PHP function. <?php function returnme($value) { return $value; } echo returnme('hello'); // outputs: hello ?>
Well that's fairly easy, as - if you done it correctly - every checkbox has a name, and if this checkbox has been ticked, the POST or GET variable will hold a value named "on", after submitting the form. A standard code to check wether it has been submitted and checked can be something like: if(isset($_POST['checkbox1']) && !empty($_POST['checkbox1'])){ do something here... } that's it.
One can use a Php admin to store information which can be easily accessed. If one uses the Php my admin one can have it to keep updated automatically.
Example: <?php $value = 10; $i = 0 if(is_int($value)) { while($i < $value) { echo $i; echo '<br/>'; $i++; } } ?>
Problem with using global variables in php is that they lose the the assigned value in a different php file. They only keep the global variable value in the php file in which they are declared. Instead of globals try and use $_SESSION or $_COOKIE to keep value intact across different php files in a project
# <select name="month" id="month"> # <option value="1" <?PHP if($month==1) echo "selected";?>>January</option> # <option value="2" <?PHP if($month==2) echo "selected";?>>February</option> # <option value="3" <?PHP if($month==3) echo "selected";?>>March</option> # <option value="4" <?PHP if($month==4) echo "selected";?>>April</option> # <option value="5" <?PHP if($month==5) echo "selected";?>>May</option> # <option value="6" <?PHP if($month==6) echo "selected";?>>June</option> # <option value="7" <?PHP if($month==7) echo "selected";?>>July</option> # <option value="8" <?PHP if($month==8) echo "selected";?>>August</option> # <option value="9" <?PHP if($month==9) echo "selected";?>>September</option> # <option value="10" <?PHP if($month==10) echo "selected";?>>October</option> # <option value="11" <?PHP if($month==11) echo "selected";?>>November</option> # <option value="12" <?PHP if($month==12) echo "selected";?>>December</option> # </select> # # <select name="day" id="day"> # <option value="1" <?PHP if($day==1) echo "selected";?>>1</option> # <option value="2" <?PHP if($day==2) echo "selected";?>>2</option> # <option value="3" <?PHP if($day==3) echo "selected";?>>3</option> # <option value="4" <?PHP if($day==4) echo "selected";?>>4</option> # <option value="5" <?PHP if($day==5) echo "selected";?>>5</option> # <option value="6" <?PHP if($day==6) echo "selected";?>>6</option> # <option value="7" <?PHP if($day==7) echo "selected";?>>7</option> # <option value="8" <?PHP if($day==8) echo "selected";?>>8</option> # <option value="9" <?PHP if($day==9) echo "selected";?>>9</option> # <option value="10" <?PHP if($day==10) echo "selected";?>>10</option> # <option value="11" <?PHP if($day==11) echo "selected";?>>11</option> # <option value="12" <?PHP if($day==12) echo "selected";?>>12</option> # <option value="13" <?PHP if($day==13) echo "selected";?>>13</option> # <option value="14" <?PHP if($day==14) echo "selected";?>>14</option> # <option value="15" <?PHP if($day==15) echo "selected";?>>15</option> # <option value="16" <?PHP if($day==16) echo "selected";?>>16</option> # <option value="17" <?PHP if($day==17) echo "selected";?>>17</option> # <option value="18" <?PHP if($day==18) echo "selected";?>>18</option> # <option value="19" <?PHP if($day==19) echo "selected";?>>19</option> # <option value="20" <?PHP if($day==20) echo "selected";?>>20</option> # <option value="21" <?PHP if($day==21) echo "selected";?>>21</option> # <option value="22" <?PHP if($day==22) echo "selected";?>>22</option> # <option value="23" <?PHP if($day==23) echo "selected";?>>23</option> # <option value="24" <?PHP if($day==24) echo "selected";?>>24</option> # <option value="25" <?PHP if($day==25) echo "selected";?>>25</option> # <option value="26" <?PHP if($day==26) echo "selected";?>>26</option> # <option value="27" <?PHP if($day==27) echo "selected";?>>27</option> # <option value="28" <?PHP if($day==28) echo "selected";?>>28</option> # <option value="29" <?PHP if($day==29) echo "selected";?>>29</option> # <option value="30" <?PHP if($day==30) echo "selected";?>>30</option> # <option value="31" <?PHP if($day==31) echo "selected";?>>31</option> # </select> # # <select name="year" id="year"> # <?PHP for($i=date("Y"); $i<=date("Y")+2; $i++) # if($year == $i) # echo "<option value='$i' selected>$i</option>"; # else # echo "<option value='$i'>$i</option>"; # ?> # </select>
JavaScript lives in the browser, PHP lives on the server.To pass a value from JavaScript to a PHP page, you can eitherdo an HTML form submituse AJAXIn both cases, the value is sent to the server and you write your PHP to handle it and send a response.The important thing is that the JavaScript value won't be available in PHP when you first generate the page, creating the page and handling the value submitted from the browser are two distinct steps.
$_POST is used see below for how. Firstly, in your form add a hidden feild: <input type="hidden" name="hasposted" value="true" /> Somewhere in your form. Then above the form add the following: <?php if($_POST['hasposted'] '1'){ $mycheckbox = true; } else { $mycheckbox = false; } echo '$mytext ' . $mytext . '<br />$mycheckbox '. $mycheckbox; } ?> <form method="POST" action="#"> <input type="hidden" name="hasposted" value="true" /> <label>Textbox: <input type="text" value="" name="mytext" /></label><br /> <label>Checkbox: <input type="checkbox" value="1" name="mycheckbox" /><br /> <br /> <input type="submit" value="Post" /> </form> I've posted links to W3Cschools with information on these and all other Form Elements.
To pass PHP Variable value in Jquery simpley echo that variable : Eg <script> var jQueryVariable=<?php echo $anyVariable?> </script>