I writinga PHP script with access to a MySQL data base. When I try to insert a value into the table I get this error:
Unknown column '$cat' in 'field list'
This is the script:
- Code: Select all
<?php
$host = 'localhost';
$user = 'root';
$pwd = 'palhaco';
$database = 'angobusiness';
$db = mysql_connect($host, $user, $pwd);
if (!$db) {
die('Could not connect: ' . mysql_error());
exit;
} else {
if (!mysql_select_db($database, $db)) {
die('Could not connect to database: ' . mysql_error());
exit;
} else {
echo 'Connected to database ' . $database;
}
}
if ($_POST['submit']){
$cat = $_POST['category'];
$SQL = 'INSERT INTO categories (category) VALUE ($cat)';
$result = mysql_query($SQL);
if (!$result) {
die('Could not insert the category ' . $cat . mysql_error());
} else {
echo $cat . ' inserted';
}
} else {
include 'templates/header.tpl';
include 'templates/add_cat.tpl';
include 'templates/footer.tpl';
}
?>
And this is the Table:
- Code: Select all
CREATE TABLE IF NOT EXISTS `categories` (
`catID` int(3) NOT NULL AUTO_INCREMENT,
`category` varchar(45) NOT NULL,
PRIMARY KEY (`catID`)
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
Can anyone Help me?
Thank You

