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` (
`id` NOT NULL AUTO_INCREMENT,
`name` VARCHAR( 75 ) NOT NULL,
`email` VARCHAR( 120 ) NOT NULL,
`password` VARCHAR( 65 ) NOT NULL
PRIMARY KEY ( `id` ),
UNIQUE (
`name`,
`email`
)
)";
$conn->exec($sql);
} catch(PDOException $e) {
echo $e->getMessage();
}
Inserting data:
$query = "
INSERT INTO user(
name, email, password
)
VALUES(
:name, :email, :password
)
";
try {
$statement = $conn->prepare($query);
$statement->execute(array(
":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.