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.
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.