absolute beginner-idiot needs help

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
sammyconn
Forum Newbie
Posts: 1
Joined: Mon Feb 12, 2007 3:25 pm

absolute beginner-idiot needs help

Post 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]
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post 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.
Charles256
DevNet Resident
Posts: 1375
Joined: Fri Sep 16, 2005 9:06 pm

Post by Charles256 »

got an extra comma in your query there at the end for starters.
Post Reply