Page 1 of 1

absolute beginner-idiot needs help

Posted: Mon Feb 12, 2007 6:39 pm
by sammyconn
feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


i'm an absolute beginner at this and i'm sure it's all very simple but i'm bangin my head against the proverbial here.

i'm creating a website for my missus but havin real trouble with the contact form. The hosting company provides us with a mysql database. i want to send the form data to the database. 

above the html tags i inserted this code:

Code: Select all

<?php
$db_host = "localhost";
$db_user = "";
$db_pwd = "";
$db_name = "";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
obviously with username, password etc between the " "

In the body of the html i inserted this code for my form:

Code: Select all

<?php
if (!isset($_POST['submit'])) {
?>
<form action="" method="post">
Name: <input type="text" name="name"><br>
Address 1: <input type="text" name="address1"><br>
Address 2: <input type="text" name="address2"><br>
Postcode: <input type="text" name="postcode"><br>
Telephone: <input type="text" name="telephone"><br>
Email: <input type="text" name="email"><br>
Comments: <input type="textarea" name="comments"><br>
<input type="submit" name="submit" value="Submit!">
</form>
<?php
} else {
$name = $_POST['name'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$postcode = $_POST['postcode'];
$telephone = $_POST['telephone'];
$email = $_POST['email'];
mysql_query("INSERT INTO `contact_us` (name, address1, address2, postcode, telephone, email, comments) VALUES ('$name', '$address1', '$address2','$postcode','$telephone','$email','$comments',)");
echo "Thank you, your information has been added.";
}
?>

should this work? why isn't it? any help much appreciated.


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Feb 12, 2007 6:42 pm
by Luke
first off... welcome to the forums... be sure to use the correct php tags when posting here so that your code is formatted like this:

Code: Select all

<?php
$db_host = "localhost";
$db_user = "";
$db_pwd = "";
$db_name = "";
mysql_connect($db_host, $db_user, $db_pwd);
mysql_select_db($db_name);
?>
that makes it easier for us to read. Second... read up on this function
http://us2.php.net/manual/en/function.mysql-error.php

Try that function out and let me know how it goes.

Posted: Mon Feb 12, 2007 8:01 pm
by Charles256
got an extra comma in your query there at the end for starters.