I'm new in PHP so I faced a problem, I got these rows in MySQL
+---+--------------+
|ID | published |
+---+--------------+
| 1 | TRUE |
| 2 | FALSE |
| 3 | TRUE |
+---+--------------+
For example, I want to update ID no. 2 into "TRUE" with a checkbox:
<?php
$host="localhost";
$username="root";
$password="password"; // Mysql password
$db_name="test"; // Database name
$tbl_name="chek_box_test"; // Table name
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
?>
<?php
$id = $_GET['id'];
$select = mysql_query("SELECT * FROM $tbl_name WHERE id = $id");
while($row = mysql_fetch_array($select)){
?>
<form method="post" action="checkbox_test.php?id=<?php echo $id; ?>">
<input type="checkbox" name="publish" <?php
if($row['publish'] == TRUE){
echo "checked='checked'";
}
?>
/>
<input type='hidden' name='id' value="<?php echo $row['id']; ?>" />
<input type="submit" name="submit" value="Update"></form><?php } ?>
<?php
if(isset($_POST['submit'])){
echo $publish = ($_POST['publish'] == 1) ? TRUE : FALSE;
$id=$_POST['id'];
$query = mysql_query("UPDATE $tbl_name SET publish = '$publish' WHERE id =$id");
}
?>
My problem is if I check that PHP it only give me 'FALSE' value. I want that if I check and click submit it will give me "TRUE" or "FALSE".
Please help me to do this. Any useful advice will be appreciated.
publishedactually hold? Tinyint (0|1), enum('yes','no') or enum('TRUE','FALSE'). You are mixing uptrueandyes.