1048 Column 'car_name' cannot be null'

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

PhPClueless
New php-forum User
New php-forum User
Posts: 4
Joined: Thu Apr 10, 2014 10:14 am

1048 Column 'car_name' cannot be null'

Postby PhPClueless » Tue Apr 15, 2014 9:56 am

I'm getting this error code how can i fix it I'm posting vales from a form the value for car_name is a word so i don't understand the null business I've checked the name on the form and and the sql code so it matches, how does this error occur I'm trying to do an insert statement with PDO.

Code: Select all

// database connection
$db = new PDO("mysql:host=$mysql_hostname;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// new data
$sql = "INSERT INTO CARS(car_name,
            doors,
            transmission,
            fuel_type,
            total,available) VALUES (
            :car_name,
            :doors,
            :transmission,
            :fuel_type,
            :total,
         :available)";
      
$query = $db->prepare( $sql );
$query->execute( array( ':car_name'=>$car_name, ':doors'=>$doors, ':transmission'=>$transmission, ':total'=>$total, ':fuel_type'=>$fuel_type,':available'=>$available,  ) );
$newId = $pdo->lastInsertId();
?>
:help: Thank you

Return to “PHP coding => General”

Who is online

Users browsing this forum: No registered users and 1 guest