Crowds
10-03-2005, 10:32 PM
Hi,
I have been going through some online tutorials for using php to create a new table in mysql. I am running sokkit on my home pc with mysql installed there so i am testing the scripts at http://localhost/
I keep getting this error
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host '$dbhost' (11001) in C:\sokkit\site\phptestarea\install.php on line 10
I kinda know what area of the script im going wrong in but i dont know why.
I have built a form to input data for the conection to mysql. (index.php)
And my form action asks for (install.php)
Here is the form
<form action="install.php" method="get" name="databaseinfo">
<label>
<div align="right">Database Host:
<input type="text" name="dbhost" value="dbhost"/>
</div>
</label>
<label>
<div align="right">Database Name:
<input type="text" name="dbname" value="dbname"/>
</div>
</label>
<label>
<div align="right">Database Username:
<input type="text" name="dbuser" value="dbuser"/>
</div>
</label>
<label>
<div align="right">Database Password
<input type="password" name="dbpass" value="dbpass"/>
</div>
</label>
<label>
<div align="right">Submit
<input type="submit" name="Submit" value="Submit" />
</div>
Not sure if i should be using a $ before dbpass and dbuser etc
Here is the install.php
<html>
<body>
<?php
// install.php: seting up you database details and creating a new table
// (1) connect to the server
// enter your database details: below in 'localhost' 'username' and 'password'
if( mysql_connect( '$dbhost', '$dbuser', '$dbpass' ) )
echo( "Connected to database.<br>\n" );
else
die( "Error! Could not connect to server: " . mysql_error() );
// (2) select the database: Enter the name of your database below 'database_name'
if( mysql_select_db( '$dbname' ) )
echo( "Selected the database.<br>" );
else
die( "Error! Could not select the database.<br>Please Check your connection details: " . mysql_error() );
// (3) create the table: If you have connected to server succsesfully then the Table below
// Will Be created With table name as 'gallery_bio' Art/photo title 'title'
// submitters name and age 'name' 'age' email address 'email' and their Biography 'bio'
// and website 'www'
// the VARCHAR() is the number of charecters available for each field. This is why 'age'
// only 3
$create_query = "CREATE TABLE `gallery_bio` ( `title` VARCHAR(30), name VARCHAR(40),
`age` VARCHAR(3), `email` VARCHAR(40), `bio` VARCHAR(100) `www` VARCHAR (40),
`id` INT AUTO_INCREMENT, UNIQUE (`id`) )";
if( mysql_query( $create_query ) )
echo( "Table created successfully.<br>" );
else
die( "Error! Could not create table: " . mysql_error() );
// put in dummy values
$insert_query = "INSERT INTO `gallery_bio`
( `title`, `name` , `age`, `email` , `bio`) VALUES
( 'S-C Admin' , '---', '---','admin@surviving-chesterfield.co.uk', 'Administrator For surviving Chesterfield' ) ";
if( mysql_query( $insert_query ) )
echo( "Values inserted successfully." );
else
die( "Error! Could not insert values: " . mysql_error() );
?>
</body>
</html>
My ultimate aim is to create a data base of biogs for artists/photographers that submit there work to an online gallery and to call the correct biog depending on what image is shown. But one step at a time... i need to get my head around php and mysql connections first. Can anyone see where i am going wrong. I think i am messing up with variables somewhere :(
I have been going through some online tutorials for using php to create a new table in mysql. I am running sokkit on my home pc with mysql installed there so i am testing the scripts at http://localhost/
I keep getting this error
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host '$dbhost' (11001) in C:\sokkit\site\phptestarea\install.php on line 10
I kinda know what area of the script im going wrong in but i dont know why.
I have built a form to input data for the conection to mysql. (index.php)
And my form action asks for (install.php)
Here is the form
<form action="install.php" method="get" name="databaseinfo">
<label>
<div align="right">Database Host:
<input type="text" name="dbhost" value="dbhost"/>
</div>
</label>
<label>
<div align="right">Database Name:
<input type="text" name="dbname" value="dbname"/>
</div>
</label>
<label>
<div align="right">Database Username:
<input type="text" name="dbuser" value="dbuser"/>
</div>
</label>
<label>
<div align="right">Database Password
<input type="password" name="dbpass" value="dbpass"/>
</div>
</label>
<label>
<div align="right">Submit
<input type="submit" name="Submit" value="Submit" />
</div>
Not sure if i should be using a $ before dbpass and dbuser etc
Here is the install.php
<html>
<body>
<?php
// install.php: seting up you database details and creating a new table
// (1) connect to the server
// enter your database details: below in 'localhost' 'username' and 'password'
if( mysql_connect( '$dbhost', '$dbuser', '$dbpass' ) )
echo( "Connected to database.<br>\n" );
else
die( "Error! Could not connect to server: " . mysql_error() );
// (2) select the database: Enter the name of your database below 'database_name'
if( mysql_select_db( '$dbname' ) )
echo( "Selected the database.<br>" );
else
die( "Error! Could not select the database.<br>Please Check your connection details: " . mysql_error() );
// (3) create the table: If you have connected to server succsesfully then the Table below
// Will Be created With table name as 'gallery_bio' Art/photo title 'title'
// submitters name and age 'name' 'age' email address 'email' and their Biography 'bio'
// and website 'www'
// the VARCHAR() is the number of charecters available for each field. This is why 'age'
// only 3
$create_query = "CREATE TABLE `gallery_bio` ( `title` VARCHAR(30), name VARCHAR(40),
`age` VARCHAR(3), `email` VARCHAR(40), `bio` VARCHAR(100) `www` VARCHAR (40),
`id` INT AUTO_INCREMENT, UNIQUE (`id`) )";
if( mysql_query( $create_query ) )
echo( "Table created successfully.<br>" );
else
die( "Error! Could not create table: " . mysql_error() );
// put in dummy values
$insert_query = "INSERT INTO `gallery_bio`
( `title`, `name` , `age`, `email` , `bio`) VALUES
( 'S-C Admin' , '---', '---','admin@surviving-chesterfield.co.uk', 'Administrator For surviving Chesterfield' ) ";
if( mysql_query( $insert_query ) )
echo( "Values inserted successfully." );
else
die( "Error! Could not insert values: " . mysql_error() );
?>
</body>
</html>
My ultimate aim is to create a data base of biogs for artists/photographers that submit there work to an online gallery and to call the correct biog depending on what image is shown. But one step at a time... i need to get my head around php and mysql connections first. Can anyone see where i am going wrong. I think i am messing up with variables somewhere :(