i'm trying to build a contact form so people can reach me and i want to save the data to mySQL database, but i'm receiving the following message when trying to use the contact form and submit
the data.
"Could not connect: Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)"
<?php
// Pick up the form data and assign it to variables
$name = $_POST['name'];
$email = $_POST['email'];
$topic = $_POST['topic'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'contact@mysite.com';
$subject = "New message: $topic";
$message = "$name said: $comments";
$headers = "From: $email";
// Open database connection
$conn = mysql_connect('mysql3.freehostia.com', '*****', '*****');
mysql_select_db('********');
if (!$conn)
{
die('Could not connect: ' . mysql_error());
}
// Insert data
$query = "INSERT INTO submissions (name, email, topic, comments) ...
VALUES ('$name', '$email', '$topic', '$comments')";
mysql_query($query);
// Close connection
mysql_close($conn);
// Redirect
header("Location: success.html");
i have replaced my personal data with "*****"
thanks!