Hello,
I have written a script for my company that requires users to enter their details for the asset register. My program is all working well, except that if they leave an entry blank and press SUBMIT then it adds blank entries to the database. What I would like is to have the fields maked as compulsory and will not let anyone continue until at least something is entered. I am new to PHP and so would like some help on where to put the code. I have put a copy of the script up here (it is very simple for now, but once it is working correctly I will change the design of the form.. I would like to make ALL the fields compulsory.
Here is the code.
<HTML>
<HEAD>
<TITLE>Asset Register</TITLE>
</HEAD>
<BODY>
<?php
if ( !isset( $POST['submit'] ) )
{
echo <<< EOF
<B><FORM ACTION="{$SERVER['PHP_SELF']}" METHOD="post">
<H1><CENTER><B><FONT SIZE="10" COLOR="#3366FF">Asset Register</FONT></B></CENTER></H1>
<BR><BR>
<B>Please fill in all your details as clearly as possible. This will enable us to keep a clear record of what laptop s or equipment you have. If you have more than one laptop or other machine please use a SEPERATE sheet for both.</B>
<BR><BR>
Please do NOT add Printers, Monitors etc. Only LAPTOPS and PC's.
<BR><BR>
<p align="left"><span style="background-color: #FFFFFF"><font face="Arial">Full Name 
</font></span><font color="#FFFFFF" face="Arial">
<span style="background-color: #0000FF"><align="left"><INPUT TYPE="text" NAME="fullname" size="20"></span></font><span style="background-color: #FFFFFF"><font face="Arial">(i.e Joe Bloggs)
<BR>Location
</font></span><font color="#FFFFFF" face="Arial">
<span style="background-color: #0000FF"><INPUT TYPE="text" NAME="location" size="20"></span></font></p>
<P align="left">
<span style="background-color: #FFFFFF"><font face="Arial">Machine Make
</font></span><font color="#FFFFFF" face="Arial">
<span style="background-color: #0000FF"><align="left"> <INPUT TYPE="text" NAME="machinemake" size="20"></span></font><span style="background-color: #FFFFFF"><font face="Arial"> (i.e TOSHIBA)<BR>Machine Type
</font></span><font color="#FFFFFF" face="Arial">
<span style="background-color: #0000FF"> <INPUT TYPE="text" NAME="machinetype" size="20"></span></font><span style="background-color: #FFFFFF"><font face="Arial"> (i.e 8100)<BR>Asset Number
</font></span><font color="#FFFFFF" face="Arial">
<span style="background-color: #0000FF"> <INPUT TYPE="text" NAME="assetnum" size="20"></span></font><span style="background-color: #FFFFFF"><font face="Arial"> (Enter 0 if none)<BR>Serial Number</font><font face="Tahoma">
</font> </span><font color="#FFFFFF"><span style="background-color: #0000FF"><INPUT TYPE="text" NAME="serialnum" size="20"></span></font><span style="background-color: #FFFFFF">
</span><span style="background-color: #0000FF"> <BR></span><BR>
<input type="submit" name="submit" value="Submit!"> <INPUT TYPE="reset" value ="Reset">
</FORM></B>
EOF;
}
else
{
$fullname = trim( $POST['fullname'] );
$location = trim( $POST['location'] );
$machinetype = trim( $POST['machinetype'] );
$machinemake = trim( $POST['machinemake'] );
$assetnum = trim( $POST['assetnum'] );
$serialnum = trim( $POST['serialnum'] );
$cnx = mysql_connect("localhost", "root", "" ) or die("connection error" );
mysql_select_db("emeaasset", $cnx) or die("DB error" );
$query = "INSERT into asset VALUES ('$fullname', '$location', '$machinetype', '$machinemake', '$assetnum','$serialnum')";
mysql_query($query) or die("query error" );
echo "THANKYOU .. The information has been sucessfully entered into the database.";
}
?>
</BODY>
</HTML>