nishmgopal Posted March 16, 2009 Share Posted March 16, 2009 Hi guys, I have my form: <form id="form2" method="post" action="do_addjob.php"> <div id="table"><table width="200" border="0"> <tr> <td>Project Role Name</td> <td> </td> <td> </td> </tr> <tr> <td><label> <input type="text" name="pname1" id="pname1" compulsory="yes"/> </label></td> <td><label> <input type="submit" name="submit" id="submit" value="Proceed" /> </label></td> <td><label></label></td> </tr> </table> and this is the action page: $projectname = $_POST['pname1']; if (isset($_REQUEST['submit'])) { # THIS CODE TELL MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $query = "INSERT INTO conmg.Job_ID (Job_ID, Job_Name) VALUES (NULL, '$projectname')"; if($result = mysql_query($query)) { echo "$projectname has been added, please fill in the details below:"; } else { echo "ERROR: ".mysql_error(); } } Is there anyway to display an error message if the projectname field was left empty? because right now even if the field is empty it gets added to the database. thanks Link to comment https://forums.phpfreaks.com/topic/149722-how-to-have-required-fields-in-my-html-form/ Share on other sites More sharing options...
supanoob Posted March 16, 2009 Share Posted March 16, 2009 wouldnt a simple if statement do it? if ($field == '') { echo "field empty"; DIE(); } ?? Link to comment https://forums.phpfreaks.com/topic/149722-how-to-have-required-fields-in-my-html-form/#findComment-786240 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.