Form not showing from php code

Hi i am very new to php and i’ve been working hard on the following code but i can’t seem to get the form to show up, i’ve tried to modify the code and look very closely to see if i’m missing anything but nothing found, i know the table code is all red in Dreamweaver but can’t find the key, need help!!! :’(

[php]

Commentaires <?php include ("Menu.php") ?>

Commentaires

<?php //connect to the database mysql_connect ("localhost", "reationa_guest", "guestbook14"); mysql_select_db("reationa_guestbook"); //******************************************* //form and add stuff area echo "

Ajouter un commentaire

"; if ($_POST['postbtn']) { $name = strip_tags($_POST['nom']); $courriel = strip_tags($_POST['courriel']); $message = strip_tags($_POST['message']); if ($nom && $courriel && $message) { $date = date("F d, Y"); //add to the database mysql_query("INSERT INTO guestbook1 VALUES ('', '$nom', '$courriel', '$message', '$date')"); echo "Votre commentaire à été ajouté";} else { echo "Il semble manquer de l'information"; } echo "
Nom:
Courriel:
Message:
"; } //******************************************* //display stuff area $query = mysql_query("SELECT * FROM guestbook1 ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0) { echo "
"; while ($row = mysql_fetch_assoc($query) ) { $id = $row['id']; $nom = $row['nom']; $courriel = $row['courriel']; $message = $row['message']; $date = $row['date']; $message = n12br ($message); echo "
Par $nom - le $date
$message

"; }} else echo "Aucun message n'a été trouvé"; //******************************************* mysql_close(); ?> [/php]

Are you posting a different form to this page?

If not, the reason your form is not showing is that your form is inside:[php]if($_POST[‘postbnt’]) {[/php] … and you will need to move your form outside of the if structure.

In addition, this line should be changed to:[php]if(isset($_POST[‘postbtn’])) {[/php]

You do not have a closing textarea tag and this will also cause the form to not display properly.

You are using XHTML 1.0 Transitional and this requires a row and column attribute for your textarea.

I know you said that your a very new to php and I am assuming that his is a learning project. If you plan to use this for a production site, you must sanitize your $_POST variables before using them in your query - using strip_tags is not enough. Also it is generally considered inappropriate to use a table for simple layout like this. For a production site, I would change to positioned divs.

Please let me know if this doesn’t work or if you have any questions.

jay

You have your form wrapped in the first if() statement.
and malasho is correct you should do if(isset())

try this…

[php]

Commentaires <?php include ("Menu.php") ?>

Commentaires

<?php //connect to the database mysql_connect ("localhost", "reationa_guest", "guestbook14"); mysql_select_db("reationa_guestbook"); //******************************************* //form and add stuff area echo "

Ajouter un commentaire

"; if (isset($_POST['postbtn'])) { $name = strip_tags($_POST['nom']); $courriel = strip_tags($_POST['courriel']); $message = strip_tags($_POST['message']); if ($nom && $courriel && $message) { $date = date("F d, Y"); //add to the database mysql_query("INSERT INTO guestbook1 VALUES ('', '$nom', '$courriel', '$message', '$date')"); echo "Votre commentaire à été ajouté"; } else { echo "Il semble manquer de l'information"; } } else { echo "
Nom:
Courriel:
Message:
"; } //******************************************* //display stuff area $query = mysql_query("SELECT * FROM guestbook1 ORDER BY id DESC"); $numrows = mysql_num_rows($query); if ($numrows > 0) { echo "
"; while ($row = mysql_fetch_assoc($query) ) { $id = $row['id']; $nom = $row['nom']; $courriel = $row['courriel']; $message = $row['message']; $date = $row['date']; $message = n12br ($message); echo "
Par $nom - le $date
$message

"; }} else { echo "Aucun message n'a été trouvé"; } //******************************************* mysql_close(); ?> [/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service