Creating Table in mySQL database using PHP script.

daveckw

New member
Joined
Apr 2, 2005
Messages
2
Can someone tell me how to create a table using PHP script.
I have done this but the table was not created. Can someone tell me what I have done wrong.?

<html>
<head>
<title>Creating favorite table </title>
</head>
<body>
<h3> Creating the favorites table for firstdb </h3>
<br>
<?php
print ("about to make connection");
require("openfirstdb.php");

$tname = "favorites";
$fields =
"favorite_id INT UNSIGNED NOT NULL AUTO_INCREMENT";
$fields = $fields .
"PRIMARY KEY, title char(50) NOT NULL, ";
$fields = $fields . "description char(50) NOT NULL";
$query="CREATE TABLE $tname ($fields)";

print("The query is: $query");

if (mysql_db_query($DBname,$query,$link)) {
print ("The table, $tname, was created");
print (" successfully.<br>\n");
}
else {
print ("The table, $tname, was not created.");
print (" <br>\n");
}
mysql_close($link);
?>
</body></html>

The table was not created. I am so confused now.
 
What is the exact error that is produced? It might help setting your php script to show errors on everything (including notices)
 
Oh, I found out that if I changed mysql_db_query($DBname,$query,$link) to mysql_query($query), the table was created succesfully.:eek:
 
Back
Top