Hey Everyone,
I have a config.php file which has my connection information located in it. And I was wondering how I could include that file into my script below (In Bold), without having to reconnect to my database.
It's probably something very simple like require_once ("../config.php"). But I have no clue as to what it would be. I've searched the internet many times, but came up with nothing.
<?php
[B]$con = mysql_connect("localhost","username","password");[/B]
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
// Create database
if (mysql_query("CREATE DATABASE test1",$con))
{
echo "Database created";
}
else
{
echo "Error creating database: " . mysql_error();
}
// Create table
mysql_select_db("test1", $con);
$sql = "CREATE TABLE Persons
(
FirstName varchar(15),
LastName varchar(15),
Age int
)";
// Execute query
mysql_query($sql,$con);
mysql_select_db("test1", $con);
$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "1 record added";
mysql_close($con)
?>
Any help would be appreciated!
Thanks in Advance!
- Michael