mysql - how to store checkbox item in a database through php -
i coading huge html form store data in database through php checkbox code not working
////check box code////
<li>mother </li><table><tr><td><input type="checkbox" name="mdeceased" value="deceased">deceased</td> <td><input type="checkbox" name="malive" value="alive">alive</td></tr> <tr><td><input type="checkbox" name="mretired" value="retired">retired</td> <td><input type="checkbox" name="minservice" value="inservice">in service</td> <td><input type="checkbox" name="mbusiness" value="business">business</td></tr>
///php code checkbox making variable , using in query ///
$mysql = new mysqli('localhost','root','ramsha','scholarships_system') or die ('you\'re dead'); if(!empty($_post['submit'])) { $mdeceased =$_post['mdeceased']; $malive = $_post['malive']; $mretired = $_post['mretired']; $minservice = $_post['minservice']; $mbusiness = $_post['mbusiness']; $query = "insert student _details values('$mdeceased','$malive','$mretired','$minservice','$mbusiness')"; if($updatedb = $mysql->query($query) or die($mysql->error)) { echo "congrats!"; }
///error coming /// notice: undefined index: mdeceased in c:\wamp\www\student form filling\htmlform.php on line 91
only $alive accepting do
i ended open <input>
tags , did null check. started working.
problem trying save variable never set/initialized.
<?php $mysql = new mysqli('localhost','root','subha#143','test') or die ('you\'re dead'); if(isset($_post['submit'])) { $mdeceased =isset($_post['mdeceased'])?$_post['mdeceased']:null; $malive = isset($_post['malive'])?$_post['malive']:null; $mretired = isset($_post['mretired'])?$_post['mretired']:null; $minservice = isset($_post['minservice'])?$_post['minservice']:null; $mbusiness = isset($_post['mbusiness'])?$_post['mbusiness']:null; $query = "insert student_details values('$mdeceased','$malive','$mretired','$minservice','$mbusiness')"; if($updatedb = $mysql->query($query) or die($mysql->error)) { echo "congrats!"; } }else{echo("post not set");} ?>
Comments
Post a Comment