I’m trying to add on to my news feature by creating a feedback form. I think in order to do this, I would need to come up with some code that would create a new table each time I submit news.
I checked w3schools, found some code and changed it around:
<?php
$con = mysql_connect("blah blah blah");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create table
mysql_select_db("commentbox", $con);
$sql = "CREATE TABLE comment1
id int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
Date date,
Name varchar(30),
Message text
)";
// Execute query
mysql_query($sql,$con);
?>
(I’m not sure if the message and date ones are right so let me know if they need to be fixed).
Anyway, would it be possible to automatically create a new database without having to go in and rename “comment1” to “comment2” myself, but have it do that automatically?
Ok the code works to create a new table, but how do i automatically create a another one each time I visit this page? Is it possible to use a primary key from a different table?
<?php
$con = mysql_connect("blah blah blah");
mysql_select_db("commentbox", $con);
$sql = "CREATE TABLE Something
(
id int NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
Name varchar(30),
Message text,
Date date
)";
// Execute query
mysql_query($sql,$con);
mysql_close($con);
?>