The connection string should work and it is not throwing an error? The html page shows up and I can enter data but it is not written to the db?
if ( isset ( $first_name ) && isset ( $state )&& isset ($last_name)) {
//check input here
$dberror= "";
$ret = add_to_database ($first_name, $state, $last_name, $dberror );
if ( ! $ret )
print "Error $dberror<BR>";
else
print "Thanks you very much";
}
else {
write_form();
}
function add_to_database ($first_name, $state, $last_name, &$dberror){
$username = "olivia77_draspen";
$password = "wolly";
$hostname = "localhost";
$db = "olivia77_homes";
$link = mysql_connect($hostname, $username, $password);
// or die("Unable to connect to MySQL");
if ( ! $link ) {
$dberror ="Couldn't connect to the server";
return false;
}
if ( ! mysql_select_db( $db, $link )) {
$db_error = mysql_error();
return false;
}
$query = "INSERT INTO fosters_homes ( first_name, state, last_name)
values ( '$first_name', '$state', '$last_name' )";
if ( ! mysql_query( $query, $link ) ) {
$dberror = mysql_error();
return false;
}
return true;
}
function write_form() {
global $PHP_SELF;
print "<form method=\"POST\">\n";
print "<input type=\"text\" name=\"first_name\">";
print "The first name you would like<p>\n";
print "<input TYPE=\"text\" name-\"last_name\">";
print "Your last_name address<p>\n";
print "<select name=\"state\">";
print "\t<option value=\"CA\">CA\n";
print "\t<option value=\"MN\">MN\n";
print "</select>\n";
print "<input type=\"submit\" value=\"submit!\">\n</form>\n";
// print "<input type=\"submit\" value=\"submit!\">\n";
// print "$query\n</form>\n";
}
//mysql_close($link);
?>