Jump to content

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.