Author Topic: So stuck (check marks in mysql)  (Read 345 times)

0 Members and 1 Guest are viewing this topic.

Offline saragothTopic starter

  • Irregular
  • Posts: 4
    • View Profile
So stuck (check marks in mysql)
« on: February 18, 2010, 03:14:04 PM »
Ok I'm new to this obviously, I'm trying to wrap my mind around how to display a check mark when I do my query page. What I'm trying to do is have staff fill out a form, there are check boxes on this form..

<td><form name="form1" action="insert.php" method="post">
<input type="checkbox" name="fac_trans_switch_dca_day" id="fac_trans_switch_dca_day">
<input type="checkbox" name="fac_ups_dca_day" id="fac_ups_dca_day">

in the insert.php here is my INSERT stuff

$sql="INSERT INTO facility (fac_trans_switch_dca_day,  fac_ups_dca_day)
VALUES
('$_POST[fac_trans_switch_dca_day]',
'$_POST[fac_ups_dca_day]')";

each of these are in the mysql db as TINYINT(1)

The form works, I can fill it out and it goes through and I see the record but checkboxes have a value of 0 regardless if they are checked or not.

Looking for a little direction here and all I've gotten so far in my search is "use bit" and "don't use bit use tinyint(1)" really about to lose my mind! =(

thanks,

Jeremy





Offline roopurt18

  • Guru
  • Fanatic
  • *
  • Posts: 3,658
  • Gender: Male
  • le sigh
    • View Profile
    • rbredlau
Re: So stuck (check marks in mysql)
« Reply #1 on: February 18, 2010, 04:40:27 PM »
Quote
<td><form name="form1" action="insert.php" method="post">
<input type="checkbox" name="fac_trans_switch_dca_day" id="fac_trans_switch_dca_day" value="true" />
<input type="checkbox" name="fac_ups_dca_day" id="fac_ups_dca_day" value="true" />

Quote
$t = 'fac_trans_switch_dca_day';
$fac_trans_switch_dca_day = array_key_exists( $t, $_POST ) && $_POST[$t] === 'true' ? 1 : 0;
$t = 'fac_ups_dca_day';
$fac_ups_dca_day = array_key_exists( $t, $_POST ) && $_POST[$t] === 'true' ? 1 : 0;
$sql="INSERT INTO facility (fac_trans_switch_dca_day,  fac_ups_dca_day)
VALUES
( {$fac_trans_switch_dca_day}, {$fac_ups_dca_day} )";

Offline saragothTopic starter

  • Irregular
  • Posts: 4
    • View Profile
Re: So stuck (check marks in mysql)
« Reply #2 on: February 22, 2010, 10:38:46 AM »
Quote
<td><form name="form1" action="insert.php" method="post">
<input type="checkbox" name="fac_trans_switch_dca_day" id="fac_trans_switch_dca_day" value="true" />
<input type="checkbox" name="fac_ups_dca_day" id="fac_ups_dca_day" value="true" />

Quote
$t = 'fac_trans_switch_dca_day';
$fac_trans_switch_dca_day = array_key_exists( $t, $_POST ) && $_POST[$t] === 'true' ? 1 : 0;
$t = 'fac_ups_dca_day';
$fac_ups_dca_day = array_key_exists( $t, $_POST ) && $_POST[$t] === 'true' ? 1 : 0;
$sql="INSERT INTO facility (fac_trans_switch_dca_day,  fac_ups_dca_day)
VALUES
( {$fac_trans_switch_dca_day}, {$fac_ups_dca_day} )";

You are the friggen man!