Jump to content

send form data to a mysql database using php?


logiclab

Recommended Posts

Hi,

 

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_I_send_form_answer3591.html

 

but hit the wall.

 

The form is on the top right of http://www.jvassgallery.com

 

and 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

 

 
    <!-------------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------------>

 

The MYSQL database I created is named email but phpmyadmin is calling it jvassgal_email so I am confused already.

 

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

 

 

<?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);
?>

 

This has me pulling my hair out. Need help, please.

 

Thanks to all!

 

logiclab

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.