I have a form that collects the user's Name, Email for a future newsletter. I know almost zero PHP and have been using a tutorial at
http://www.apluskb.com/scripts/How_can_ ... r3591.html
but hit the wall.
when I try to add a name and email, I get this error.
Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL server host '(jvassgal_email).mysql.jvassgallery.com' (1) in /home/jvassgal/public_html/formindb.php on line 2
Could not connect: Unknown MySQL server host '(jvassgal_email).mysql.jvassgallery.com' (1)
the form looks like this
Code: Select all
<!-------------begin form------------>
<FORM ACTION="formindb.php" METHOD="POST" NAME="contact_form">
<span class="optin">Name</span><br>
<input name="name" type=text size="18">
<br>
<span class="optin">Email</span><br>
<input name="email" type=text size="18"><br>
<br>
<input class="optin" type="submit" value="Gallery News" name="Submit">
</FORM>
<!-------------end form------------>
In the first line below, ($con) I tried replacing jvassgal_email with localhost per the host's suggestion but I don't think I put localhost in the right place.
The php file formindb.php is on the server and the code is
Code: Select all
<?php
$con = mysql_connect("(jvassgal_email).mysql.jvassgallery.com","mylogin","mypassword"); //Replace with your actual MySQL DB Username and Password
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("email", $con); //Replace with your MySQL DB Name
$name=mysql_real_escape_string($_POST['name']); //This value has to be the same as in the HTML form file
$email=mysql_real_escape_string($_POST['email']); //This value has to be the same as in the HTML form file
$sql="INSERT INTO email_data (name,email) VALUES ('$name','$email')"; /*form_data is the name of the MySQL table where the form data will be saved.
name and email are the respective table fields*/
if (!mysql_query($sql,$con)) {
die('Error: ' . mysql_error());
}
echo "The form data was successfully added to your database.";
mysql_close($con);
?>
Thanks to all!
logiclab