Reputation: 2763
I am try to send my checkbox value to my database if it's checked value "Yes" else if not checked value "No"
I try this
<input type="checkbox" name="hidesCompany" id="hidesCompany" class="checkBoxStyle" value="Yes">
and this the PHP to post
$hidesCompany = $_POST['hidesCompany'];
if($hidesCompany !='Yes'){
$hidesCompany='No';
}
but the problem here it always go to database as '0' not 'yes' or 'no'
Upvotes: 0
Views: 152
Reputation: 11062
Sounds like the hidesCompany
column in your database table has some kind of INT
type rather than being TEXT
or VARCHAR
etc.
Upvotes: 0
Reputation: 415
you should try this
$hidesCompany = '';
if(isset($_POST['hidesCompany']) && !empty($_POST['hidesCompany']))
{
$hidesCompany = $_POST['hidesCompany'];
}
else
{
$hidesCompany='No';
}
Upvotes: 1