The code is in the zip file too. Just in case it got scrambled or something.
PHP Code:
<?php
echo "
<HTML>
<HEAD></HEAD>
<BODY>";
// Define your connection variables below
$dbhost = "localhost"; // Usually localhost or 127.0.0.1
$dbname = "Database_Name";
$dbuser = "username";
$dbpass = "password";
// Define your table name below and we will create a table too
$tablename = "Your_Table";
// These will be the columns inside your table
$col1 = "username";
$col2 = "email";
// Let's insert a username and password in the above
$col1insert = "Your_name";
$col2insert = "Your_email";
// We are gonna try to connect here
$connect = mysql_connect("$dbhost", "$dbuser", "$dbpass")
or die ("Could not connect to MySQL" . mysql_error());
/* Assuming your running locally and not on the web
We will try to create the database now
If you are using this code on the internet comment the code out
below to create a database and create the database from the control panel then execute this code.*/
$create = mysql_create_db("$dbname")or die("Create Error: ".mysql_error());
if($create)
echo "<b>$dbname created!! </b><br>";
// Now let us select the database we just created
mysql_select_db ("$dbname")
or die ("Could not select database" . mysql_error);
// Ok Let's make that table I promised you now
$create_table = mysql_query("CREATE TABLE $tablename
(id INT NOT NULL AUTO_INCREMENT, PRIMARY KEY(id), $col1 VARCHAR(16),
$col2 VARCHAR(16))")or die("Create table Error: ".mysql_error());
// Display result below
if($create_table == true)
echo "<b>Table $tablename created</b><br>";
// Adding fields to the columns now
$result = mysql_query("INSERT INTO $tablename ($col1, $col2)
VALUES ('$col1insert','$col2insert')")or die("Insert Error: ".mysql_error());
// Display result
if($result == true)
echo "<b>$col1insert inserted into $col1<br>
$col2insert inserted into $col2</b><HR width=\"50%\" align=\"left\">";
// Diplaying your database table below. Pretty ain't it ;)
$result = mysql_query( "SELECT * FROM $tablename" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "<b><br><br><br>Here is your table inside of $database $dbname.<br> Good Job!!</b>\n";
print "<br><br><table width=200 border=1>\n";
while ($get_info = mysql_fetch_row($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=3/><b>$field</b></font></td>\n";
print "</tr>\n";
}
print "</table>\n";
// Closing connection
mysql_close($connect);
echo "
</BODY>
</HTML>";
?>
Bookmarks