jkost Posted February 8, 2010 Share Posted February 8, 2010 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 = '[email protected]'; $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! Link to comment https://forums.phpfreaks.com/topic/191400-need-help-with-a-php-contact-form/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.