i wrote this little piece of code (snippet) to show you how you can check for data connection on your scripts. lets say you have a script and you want to confirm that you are able to connect to the database with the username, password and hostanme that a user has provided. you usually see these type of form on install scripts. well, i was just writing an install script and i thought i put this php snippet here just incase someon might find it useful. all you have to do is copy and paste this code into your texteditor like notepad and save the file as connection.php and upload to your server, then the form will ask you for your database hostname, username, password
<style type="text/css">
<!--
form#checkout div.row div.field
{
float: left;
width: 150px;
margin: 0px 0px 0px 0px;
padding: 0px 0px 0px 0px;
}
div.clear
{
clear: both;
}

b {
color: #000000;
}

-->
</style>
<h1>This script provided by <a href="http://www.webune.com">Webune.com</a></h1>
<hr>
<?
ini_set('display_errors', 0);

$field_name = array(

1 => 'Database Server:',
2 => 'Username:',
3 => 'Password:',
4 => 'Database Name:'

);
$field_type = array(

1 => 'text',
2 => 'text',
3 => 'password',
4 => 'text'

);

function tidy ($form_string) {
$form_string = trim(stripslashes($form_string));
return $form_string;
}

function form($error) {
?>

<form action="" method="post" id="checkout">
<?
$num_fields = 4;
global $field_name, $field_type;

if($error){
echo '<h1 style="color: red">'.$error.'</h1>';
}

for($counter =1; $counter <= $num_fields ; $counter++)
{

echo '<div class="row">
<div class="field">'.$field_name[$counter].'</div>';

switch($field_type[$counter])
{
case 'textarea':
echo '<textarea name="field['.$counter.']">'.$_POST['field'][$counter].'</textarea>
';
break;

case 'checkbox':
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">';
break;

case 'radiobutton':
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">';
break;

case 'select':
echo'
<select name="question" >
<option value="What is your favorite pet name?">What is your favorite pet name?</option>
<option value="What is your father birth date?">What is your father birth date?</option>
<option value="What is your favorite music band?">What is your favorite music band?</option>
<option value="What is your mother maiden name?">What is your mother maiden name?</option>
</select>
';
break;

case 'password':
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">
';
break;

case 'file':
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">';
break;

case 'hidden':
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">';
break;

case 'break':

break;

default:
echo '<input type="'.$field_type[$counter].'" name="field['.$counter.']" value="'.$_POST['field'][$counter].'">';
break;
}

echo'</div>
<div class="clear"></div>
</div>';

}
?>
<input type=submit name="Submit" value="Submit" />
</form>
<?php
}
// The data comes from the form in fig 4.2

if(isset($_REQUEST['Submit']))
{

# check all fields are not empty, if so, $error is true
foreach($_POST['field'] as $field => $line) {
$value = tidy($line);
if(!$value){
$error = $field_name[$field].' is empty <br>';
break;
}
//print("n<br />field[" . $field . '] ' . $value);
}

$server = trim(stripslashes($HTTP_POST_VARS['field'][1]));
$username = trim(stripslashes($HTTP_POST_VARS['field'][2]));
$password = trim(stripslashes($HTTP_POST_VARS['field'][3]));
if(!mysql_connect($server, $username, $password)){
$error = 'Unable to connect to database...';
}

if($error){
form($error);

}
else{

echo '<h1 style="color: green">Success!</h1>Connection to database successful. <a href="?step=2">Continue >> </a>';
}
}
else {
form($error);
}
?>
<hr>
We hope you found this little script usefull. if you ever need php hosting, visit our friends at <a href="http://www.webune.com">www.webune.com</a>