I am new to php and mysql, so please tell me where am I wrong.
Here is my php file :
<?php
$c=mysql_connect("localhost","sanjay","");
if(!$c)
{
die("Error in connecting to database");
}
else
{
print("Success");
}
$e="CREATE DATABASE db1";
if(!mysql_query($e,$c))
{
print("Error Creating Database");
}
else
{
echo "Database Created";
}
mysql_select_db("db1",$c);
$e1="create table t1(id int,firstname varchar(15),lastname varchar(15),age int)";
if(!mysql_query($e1,$c))
{
echo "Error creating table.";
}
else
{
echo "table created";
}
?>
I get the following output –
SuccessError Creating DatabaseError creating table.
What am I doing wrong? And what should be the correct code for the same?
I don’t see something wrong with your code, so i think the problem will be in access rights given to account. You should modify mysql access rights and
Grantthe user rights to CREATE (which is a privilege for both: database & table creation)