MySQL Error Help PLEASE?????

Codes here !

Moderators: macek, egami, gesf

reisve
New php-forum User
New php-forum User
Posts: 1
Joined: Sun Dec 09, 2012 2:12 am

MySQL Error Help PLEASE?????

Postby reisve » Sun Dec 09, 2012 2:24 am

Hi
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

Return to “mySQL & php coding”

Who is online

Users browsing this forum: Google [Bot] and 3 guests

cron