Jump to content

how to have "required" fields in my html form


nishmgopal

Recommended Posts

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.