PDO insert no longer working

Hi guys,

I’ve used these code for very long time and it works every time.
I’m trying to build a new web site from scratch, but it’s no longer working. What’s happening to my code? Is this obsoleted?

Creating table:

try {
	$sql = "CREATE TABLE `user` (
	   `name` VARCHAR( 75 ) NOT NULL,
	   `email` VARCHAR( 120 ) NOT NULL,
	   `password` VARCHAR( 65 ) NOT NULL
	 PRIMARY KEY ( `id` ),
} catch(PDOException $e) {
	echo $e->getMessage();

Inserting data:

$query = "
		name, email, password
		:name, :email, :password
try {
	$statement = $conn->prepare($query);
		":name" => $name,
		":email" => $email,
		":password" => $password
} catch(PDOException $e) {
	echo $e->getMessage();

Thanks for helping in advance, I’ve tried to solve this for half a day already.

Do you get an error message?

Thanks for reply,

I found a solution. In real life, I have more columns than this example. It has to fill value in every field. This works before but no longer works when I upgraded mySQL to the latest version.

Strange though.

It gets me two days to find out.

To be on the safe side in such case, be smart to have the fields nullable for the optional ones and handle required fields through validations. Because you never know what changes come in the software/tools/frameworks that you use without asking you :slight_smile:

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.