I am trying to create table to my database from php. I kinda trying to make a social networking site, anyway, I wrote the code and is working but new table won’t create in database, I don’t know what seems to be wrong with the code. Help will be much appreciated thanks!
<?php
$host = "host";
$user = "user";
$pswd = "password";
$dbnm = "db";
$conn = @mysqli_connect($host, $user, $pswd, $dbnm);
if (!$conn)
die ("<p>Couldn't connect to the server!<p>");
$selectData = @mysqli_select_db ($conn, $dbnm);
if(!$selectData)
{
die ("Database Not Selected");
}
$sql = "CREATE TABLE IF NOT EXIST 'friends'
(
'friend_id' INT NOT NULL auto_increment,
'friend_email' VAR CHAR(20) NOT NULL,
'password' VAR CHAR(20) NOT NULL,
'profile_name' VAR CHAR(30) NOT NULL,
'date_started' DATE NOT NULL,
'num_of_friends' INT unsigned,
PRIMARY KEY ('friend_id')
)";
$query_result = @mysqli_query($conn, $sql);
mysqli_close($conn);
?>
You need to check for errors when running scripts also, so either turn off suppression (remove the @ symbol) or else check for an error after running.
There were in fact multiple errors:
EXISTrather thanEXISTSYou had
VAR CHARas two words, rather than the correctVARCHAR(one word)