Hi all
Form:
The form is used for entering login information for a database. When the user has entered his information and clicked the "Save" button a database script is called.
Script:
The script first purpose is to validate if the user has entered any information into the form at all, that is no blank fields allowed. If information has been entered into the form fields the script connect to the database. However, as soon as i launch the page with the form, the script try to make a connection to the database, and fails since no information has yet been entered into the form. What do I do?
Form from main page:
<body>
<form action="" method="post">
DBName:<input type="text"
name="dbname" size="" value="" />
DB Host:<input type="text" name="dbhost" size="" value="" />
User Name:<input type="text" name="dbuser" size="" value="" />
Password:<input type="text" name="dbpswd" size="" value="" />
<input type="submit" name="submit" value="Save" />
</form>
<?php
include "../www/lib/sql.createtables.php";
?>
Script:
<?php
if (isset($POST['submit']))
$dbname=$POST['dbname'];
$dbhost=$POST['dbhost'];
$dbuser=$POST['dbuser'];
$dbpswd=$_POST['dbpswd'];
Here shoud be some conditional statements.
@mysql_connect($dbhost,$dbuser,$dbpswd)
or die("could not connect to MySQL server!");
@mysql_select_db($dbname)
or die("could not select MySQL database!");
echo 'Connection succeded!';
mysql_close();
?>