<?php
function htmlhead()
{
?>
<html>
<head>
<title>Registration Sent</title>
</head>
<body>
<?php
}
function foot()
{
?>
<form method="LINK" action="index.htm"><input type="submit" value="Return to home page"></form>
</body>
</html><?php
}
if ( !empty( $_POST ) ) {
$to = "xxxxx";
$subject = "Event Registration";
function stripandfilterhtml( $string )
{
if ( empty( $string ) )
return " -empty- ";
if ( is_array( $string ) )
$string = array_map( "stripandfilterhtml" , $string );
else
$string = htmlspecialchars( strip_tags( $string ) ) ;
return $string;
}
$data = array_map( "stripandfilterhtml" , $_POST );
$email = $data['email'] ;
$message = "Competitor Info: <br>Helm Name:" . $data['helmname'] . "<br>Email:" . $data['email'] . "<br>Contact Phone Number:" . $data['phone'] . "<br>Club:" . $data['club'] . "<br>Boat Class:" . $data['class'] . "<br>Sail Number:" . $data['sailno'] . "<br>Event: " . $data['event'] . "<br><br>Parents Info:<br>Name:" . $data['name'] . "<br>Can Help With:" . ( empty( $data['help'] )?" -not selected -": print_r($data['help']) ) . "<br>Contact Number:" . $data['telno'] . " <br>Email Address: " . $data['helperemail'];
$con = mysql_connect(
"XXXXX",
"XXXXX",
"XXXXX");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("reglist", $con);
$sql="INSERT INTO registrations (name, email, phone)
VALUES
('$_POST[name]','$_POST[email]','$_POST[phone]')";
if (!mysql_query($sql,$con))
{
die('Error: ' . mysql_error());
}
echo "<!--success-->";
mysql_close($con);
if ($sent){
header( "Location: " . $_SERVER["PHP_SELF"] . "?thankyou" );
} else {
header( "Location: " . $_SERVER["PHP_SELF"] . "?email_failed" );
}
}
htmlhead();
if ( isset( $_GET["thankyou"] ) ) {
?>Registration Received<?php
}
if ( isset( $_GET["email_failed"] ) ) {
?>There has been an issue with your registration, please try again. If the problem persists, please inform us through the contact webmaster link on the home page.<?php
}
foot();
?>
The email send part of the code works fine, but the add to database function doesn't. It prints the following error:
Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'test'@'XXXXX' (using password: YES) in /home/XXXXX/public_html/train.php on line 47
Could not connect: Access denied for user 'test'@'XXXXX' (using password: YES)"
$con = mysql_connect(
"XXXXX",
"XXXXX",
"XXXXX"); - line 47
The password is definitely right, as is the username. I have tried using both the web address and localhost, both return the same error. Any idea what is wrong?