Few days ago I was searching online for a way to create a PHP forum though which the visitors can leave their messages and to automatically appear on the page. I found the a code and I used it to create the PHP form, but unfortunately I discovered the that all the fields are not required means that the visitor can submit an empty message and it will be added empty
Question
ReMoN SaMiR
Hello,
Few days ago I was searching online for a way to create a PHP forum though which the visitors can leave their messages and to automatically appear on the page. I found the a code and I used it to create the PHP form, but unfortunately I discovered the that all the fields are not required means that the visitor can submit an empty message and it will be added empty
The form:
<form id="form1" name="form1" method="post" action="addwish.php"> <td><table width="760" border="0" cellpadding="3" cellspacing="1"> <tr> <td width="112" class="style13">Name:</td> <td width="633" class="style13"><input name="name" type="text" id="name" size="50" /></td> </tr> <tr> <td valign="top" class="style13">Email:</td> <td class="style13"><input name="email" type="text" id="email" size="50" /></td> </tr> <tr> <td valign="top" class="style14 style15">Wishes</td> <td class="style13"><textarea name="comment" cols="60" rows="6" id="comment"></textarea></td> </tr> <tr> <td class="style14"> </td> <td class="style14"><input type="submit" name="Submit" value="Send" /> <input type="reset" name="Submit2" value="Clear" /></td> </tr> </table></td>The Addwish.php
<?php $host="localhost"; // Host name $username="name"; // Mysql username $password="password"; // Mysql password $db_name="dbname"; // Database name $tbl_name="tablename"; // Table name // Connect to server and select database. mysql_connect("$host", "$username", "$password")or die("cannot connect server "); mysql_select_db("$db_name")or die("cannot select DB"); $datetime=date("y-m-d h:i:s"); //date time $name=$_POST['name']; $email=$_POST['email']; $comment=$_POST['comment']; $sql="INSERT INTO $tbl_name(name, email, comment, datetime)VALUES('$name', '$email', '$comment', '$datetime')"; $result=mysql_query($sql); //check if query successful if($result){ echo "Your Birthday wish has been added successfully. Thank You!"; echo "<BR>"; echo "You'll be automatically redirected to the wishes page in 1 second."; } else { echo "ERROR"; } mysql_close(); ?>Can anyone tell me how to edit the above code to make all the fields required before submitting the post into the database.
Your help is appreciated. :rose:
Link to comment
Share on other sites
5 answers to this question
Recommended Posts