English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I have successfully just created a script, I know it connects to the db and adds a record for the comments field and puts the value in. However it will not add the name and email address, I have taken all error checking because it won't seem to get past the !$var to check if the forms are empty as well. what can I do. Here is my main block of code.

$user = addslashes($user);
$email = addslashes($email);
$comments = addslashes($comments);
$dbh = mysql_connect("localhost", "admin", "password");
mysql_select_db("admin_mj", $dbh);
$addfeedback = "INSERT INTO 'feedback' (user, email, spam, comments)
VALUES ('".$user."', '".$email."', '".$spam."', '".$comments."')";
$result = mysql_query($addfeedback);
?>

Using 4.1.21 and the latest mysql.

How can I tell if the variables are not being sent from the submitted form which is as follows

2007-03-12 07:19:03 · 4 answers · asked by william_mac_13 2 in Computers & Internet Programming & Design


Your Name:  


Your Email:  



Join My Newsletter?   Yes
  No



Comments:









2007-03-12 07:19:46 · update #1

4 answers

Try this code block:

$user = addslashes($user);
$email = addslashes($email);
$comments = addslashes($comments);
$dbh = mysql_connect("localhost", "admin", "password");
mysql_select_db("admin_mj", $dbh);
$addfeedback = "INSERT INTO feedback (user, email, spam, comments) VALUES ('$user', '$email', '$spam', '$comments')";
$result = mysql_query($addfeedback);
?>

2007-03-12 11:37:47 · answer #1 · answered by Anonymous · 0 0

Looks like you still need to execute your SQL.

Like this:

$sql = "SQL HERE";
$query = mysql_query($sql) or die("Cannot query the database.
" . mysql_error());

I would also make sure it's only posting when submitted. If you have two seperate files, this is not an issue. If your using the same file, add a hidden form field named 'submitted' and give it a value of 'yes', then surround your database code with:

if($_POST['submitted'] == 'yes'){
DB code here.
}

2007-03-12 14:49:27 · answer #2 · answered by Clinton G 2 · 0 0

he error is in your form.
see u have some thing like this

where is "Name" attribute"???
Correct ur html like this
and it will work.
To be on the safe side, use $_POST['user'] on the page where u are inserting data in db. Because, if register_globals is turned off now or later, you will not be able to get value in form's user field as just $user. U will need to have $_POST['user']

2007-03-14 09:00:20 · answer #3 · answered by Atif Majid 3 · 0 0

easy, just cheat

http://www.tele-pro.co.uk/scripts/contact_form/

( just saves time and messing about )

2007-03-13 23:21:05 · answer #4 · answered by glynn.alexander 3 · 0 0

fedest.com, questions and answers