Jump to content

UPDATE table_name SET problem.


sho88

Recommended Posts

Hi guys, basically, I've got a web application I'm working on for someone; they want a system where they can book drivers, and they want a tick box where they can check the availability of a driver.

 

The check box name is "field14" and has default value of "1" for ticked and "0" for unticked.

Now, i've INSERT into the database a ticked box so in the "available" field is has "1" meaning yes, the people is available....but now the problem is if I want to tick off and say they're unavailable, how would I do that, because everytime I tick off it still represents the value of "1" and shows them as available....

Here is some code:

 

if (($field14)==1) {
echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14' value='1' checked/></p><br /><br />";
} else {
echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='14' value='0'/></p>";
}

 

I would really appreciate your help.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/217122-update-table_name-set-problem/
Share on other sites

try something like this:

 

You will have to modify your code a little.

 

By default when you submit a form with checkboxes, if its checked for instance

 

$_POST['field14'] will be equal to 'On'

 

if its not checked however

 

$_POST['field14'] will be NULL, nothing that is. 

 

btw your second input field after the else block, the name of that is just '14' rather than 'field14', that could be it too.

 

<?php
if ($field14 == 'On') {


echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14'  checked='checked'/></p><br /><br />";
} else {



echo "<p><label>ADR in Tank Class 1</label><input type='checkbox' name='field14' /></p>";
}
?>

 

as for inserting into the database with the values 1 and 0 you could do something like this:

 

<?php

$val;
  if($_POST['field14'] == 'On') {
   $val = 1;
} else if(is_null($_POST['field14'])) {
  $val = 0;
}

// qry
mysql_query("UPDATE mytable SET somefield = '$val'");

?>

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.