Hey, so basically i have to make a website and link it up to a database, so that whenever the user puts information into the payment form and hits submit, it will send and insert into the database. I’ve got that set up, but it dosnt seem to add to the database. can someone help? I will put the code below. Thanks.
[php]
<?php $username = "student"; $password = "student"; $hostname = "localhost"; // connecting to the database $db = mysql_connect($hostname,$username,$password); if (!$db) { die("Connection Failed: " . mysql_error()); } if ($db) { echo "Database Connection Status : Successful
"; } // selecting the database $db_select = mysql_select_db('antiques', $db); if (!$db_select) { die ("Failed to select database : " . mysql_error()); } if (($_SERVER['REQUEST_METHOD'] == 'POST') AND (isset($_POST['submit'] ))){ $chosen = $_POST['submit']; $FirstName = check($_POST['FirstName'],"Enter your FirstName"); $LastName = check($_POST['LastName'],"Enter your LastName"); $StreetAddress1 = check($_POST['StreetAddress1'],"Enter first street address"); $StreetAddress2 = check($_POST['StreetAddress2'],"Enter your second street address"); $TownCity = check($_POST['Town/City'],"Enter your Town/City"); $Postcode = check($_POST['Postcode'],"Enter your Postcode"); $CreditCardNo = check($_POST['CreditCardNo'],"Enter your Credit Card No"); $SecurityNo = check($_POST['SecurityNo'],"Enter your Security No"); $sql="INSERT INTO antique (`FirstName`, `LastName`, `Street Address1`, `Street Address2`, `Town/City`, `Postcode`, `Credit Card No`, `Security No`) VALUES ('{$FirstName}','{$LastName}','{$StreetAddress1}','{$StreetAddress2}','{$TownCity}','{$Postcode}','{$CreditCardNo}','{$SecurityNo}')"; if (!mysql_query($sql)) { die('Error: ' . mysql_error()); } else { echo "1 record added"; echo 'Hello ' . htmlspecialchars ( $_POST [ "FirstName" ]). ' '; echo htmlspecialchars ( $_POST [ "LastName" ]). '!' ; } mysql_close($db); } ?>
<?php
function check( $value , $problem="") {
$magic_quotes_active = get_magic_quotes_gpc();
$new_enough_php = function_exists( “mysql_real_escape_string” );
if( $new_enough_php ) {
if( $magic_quotes_active ) { $value = stripslashes( $value ); }
$value = mysql_real_escape_string( $value );
} else {
if( !$magic_quotes_active ) { $value = addslashes( $value ); }
}
if ($problem && strlen($value) == 0){
die($problem);
}
return $value;
}
?>
[/php]