Jump to content

[SOLVED] Working with Checkboxes


scarlson

Recommended Posts

I am trying to store the value of my checkbox in my mySQL database.  I have tried multiple things but nothing has worked yet.

 

In the database I have it setup to store a bool, is that what i want to do.  I imagined that checked would equal 1 and unchecked would be 0.

 

I am wanting to store the value so i can use it later in a query to see if this item was checked or not.

 

Any help or suggestions would be great.

 

Scott

Link to comment
https://forums.phpfreaks.com/topic/89011-solved-working-with-checkboxes/
Share on other sites

Ok, still not working.  Here is the code I am trying to do now:

 

<INPUT TYPE=CHECKBOX NAME="gSale" value="0">Place a check if ad is for a Garage Sale<P>

 

This is the setup for the checkbox

 

$gSale=isset($_POST['gSale'])?1:0;

This is the code I am using to get the value if it's checked or not, then using $gSale to store that in the database.  It always shows as 0

Ok, still not working.  Here is the code I am trying to do now:

 

<INPUT TYPE=CHECKBOX NAME="gSale" value="0">Place a check if ad is for a Garage Sale<P>

 

This is the setup for the checkbox

 

$gSale=isset($_POST['gSale'])?1:0;

This is the code I am using to get the value if it's checked or not, then using $gSale to store that in the database.  It always shows as 0

 

No, the value must be 1. I'd say just starting out simple:

 

<input type="checkbox" name="gSale" value="1">

<?php
$gSale = $_POST['gSale'];

if ($gSale == 1) {
// Was checked
}
?>

Ok, still not working.  Here is the code I am trying to do now:

 

<INPUT TYPE=CHECKBOX NAME="gSale" value="0">Place a check if ad is for a Garage Sale<P>

 

This is the setup for the checkbox

 

$gSale=isset($_POST['gSale'])?1:0;

This is the code I am using to get the value if it's checked or not, then using $gSale to store that in the database.  It always shows as 0

 

No, the value must be 1. I'd say just starting out simple:

 

<input type="checkbox" name="gSale" value="1">

<?php
$gSale = $_POST['gSale'];

if ($gSale == 1) {
// Was checked
}
?>

 

So I tried setting the value to 1 but I am still not getting a 1 if it's checked. 

 

So by setting the value to 1 in the checkbox tag if it's checked it will hold a value of 1?  I'm not getting it.

not working?

 

<?php
if($_SERVER['REQUEST_METHOD']=='POST')
echo "<PRE>". print_r($_POST,true) ."</PRE>";
?>    
<html>
<body>
  <form method="POST">
  <INPUT TYPE='checkbox' name='cb[]' value='0'>  
  <INPUT TYPE='checkbox' name='cb[]' value='1'>  
  <INPUT TYPE='checkbox' name='cb[]' value='2'>  
  <INPUT TYPE='checkbox' name='cb[]' value='3'>  
  <INPUT TYPE='checkbox' name='cb[]' value='4'>
  <INPUT type="submit">
  </FORM>
</body>
</html>

 

as i said, unchecked checkboxed return nothing, while checked boxes return the value.

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.