Once we have successfully connected to the database, we will need to create some tables on it. MySQL tables are a way of arranging the data, much like HTML tables!
$table = "guestbook"; // database table
// create table on database
$create = "create table $table (
id int(11) NOT NULL auto_increment,
name char(30) NOT NULL,
email char(80) NOT NULL,
comment char(250) NOT NULL,
primary key (id)
);";
mysql_query($create)
or die ("Could not create tables because ".mysql_error());
That's right, more variables! $table is the name of the database table we'll be creating and using. You can put this up the top of the script, or in an include, with your other variables for ease of use.
$name = "myname";
$email = "me@mydomain";
$comment = "testing the database";
// insert data into database
$insert = mysql_query("insert into $table values ('NULL', '$name', '$email', '$comment')", $link)
or die("Could not insert data because ".mysql_error());
Here we define the data, then use the mysql_query function to insert it into the table. The data must be entered in the correct order; we created the table in the order of id, name, email and comment, so we enter the values in the same order.Can't find what you're looking for? Try searching for it:
© 2000-2008 Xentrik.Net