|
Hi,
I am inserting some data from my checkbox, based on selection, which 1 is selected and 0 is not, both get sent to the database. But the code seems to give a successful response, but that column named 'Priority' does not yield and results and gives a blank row. This code also inserts data from a text area into the database fine and data does appear. The column in the table description called 'priority' had type varchar - it didn't work, and now 'int' and still does not work, any ideas what is wrong with this code?
<?php
$host="localhost"; // Host name
$username=""; // Mysql username
$password=""; // Mysql password
$db_name="my_db"; // Database name
$tbl_name="description"; // Table name
// Connect to server and select database.
mysql_connect('localhost', 'root')or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
if (priority != NULL) {
$priority = 1;
}
else {
$priority = 0;
}
// Get values from form
$comments=$_POST['comments'];
$priority=$_POST['priority'];
// Insert data into mysql
$sql="INSERT INTO $tbl_name(Issue, Priority)VALUES('$comments', '$priority')";
$result=mysql_query($sql);
// successfully insert data into database
if($result){
echo "Successful";
echo "<BR>";
echo "<a href='loginsuccess.php'>Back to main page</a>";
}
else {
echo "ERROR";
}
?>
|