0

morning all - amended question, as data now enters db correctly,

I'm a newbie to php/mysql, but through various articles and guides have built a form, which when submitted I want the user to be sent to a separate THANK YOU PAGE (so I can track conversions etc).

Here's the code I'm currently using, which when the form is submitted with no errors, delivers a 'THANK YOU' message on the same page:

   <?php
if(isset($error))
    {echo "<span id='Warning'>Please enter all areas marked with *</span>";}
else if (isset($sent))
    {echo "<span id='Normal'>Thank you for your enquiry, we will contact you shortly</span>";}
?>

Previously I was using the following after the mysql query (where the fields enter the db), but this sent users to the 'THANK YOU' page even if there were errors with the form they completed

header('Location: http://www.THANK-YOU-PAGE');
}
?>

Can anyone see anything glaringly wrong? I'm new to this, so any help is appreciated.

Thanks

MPelletier
  • 16,256
  • 15
  • 86
  • 137
Motley9735
  • 105
  • 1
  • 2
  • 10

1 Answers1

0

Probably, you are missing some fields values in the INSERT INTO statement. If you don't specify the fields, you have to enter exactly one value for each field, or mysql won't know which value goes in wich field. So to avoid this, try to write your statement like the following, with the fields you want to populate written in the statement.:

INSERT INTO field1, field2 VALUES ('value1', 'value2');

Anyway, your query is very insecure. You should use at least mysql_real_escape_string to escape user input. You can read about SQL injections in the same link or here. There are other alternatives that I prefer, like using PDO class of PHP.

Jose Armesto
  • 12,794
  • 8
  • 51
  • 56
  • Thanks one - I removed the header('Location: http://www.THANK-YOU-PAGE'); } from just after the my sql query and data now appears in the correct fields in the database. So I guess I don't need to do as you suggested, however, how do I know make it so when someone submits the form, they're redirected to a THANK YOU page? At present the following is used: Please enter all areas marked with *";} else if (isset($sent)) {echo "Thank you for your enquiry, we will contact you shortly";} ?> – Motley9735 Mar 06 '11 at 12:10
  • You could do it with javascript, or check this out http://stackoverflow.com/questions/1614241/redirect-after-post – Jose Armesto Mar 06 '11 at 13:45
  • You cannot redirect using `header()` after sending any HTML data. – smdrager Apr 05 '11 at 16:27