Hi all,
I am need for some desperate help.
I have created an html form - userrequest_insert_form, where the users enter data, but how do I check for blank fields and generate error messages?
This is the code for userrequest_insert_form
<html><head><title>Request Form</title></head>
<body>
Form</h3>
<form method="POST" action="userrequest_insert_record.php">
<table border="0" cellspacing="1" cellpadding="5"width="50%">
<tr>
<td>Username</td>
<td class="dr"><input type="text" name="username" ></td>
<td>Department</td>
<td class="dr"><input type="text" name="department" ></td>
<td>Phone Ext</td>
<td class="dr"><input type="text" name="phoneext" ></td>
</tr>
<tr>
<td>Location</td>
<td class="dr"><input type="text" name="location" ></td>
<td>Equipment</td>
<td class="dr"><input type="text" name="equipment" ></td>
</tr>
<tr>
<td>Subject</td>
<td class="dr" colspan=5><input size=105 type="text" name="subject" ></td>
</tr>
<tr>
<td> Fault Description</td>
<td class="dr" colspan=5><textarea name="fdescription" cols="80" rows="6" wrap="PHYSICAL"></textarea></td>
</tr>
<tr>
<td><strong>Urgency Value</strong></td>
<td class="dr"><select name="uvalue"><option value="Normal">Normal</option><option value="Critical">Critical</option>
<option value="High">High</option><option value="Low">Low</option><option value="Query">Query</option></select></td>
</tr>
</table>
<input type=submit value=Submit><input type=reset>
</form>
<form method="POST" action="userrequest_dbase_interface.php">
<input type="submit" value="Return to Main Menu" align="left">
</form>
</td></tr></table>
</body>
</html>
And, this is the code for inserting the data into the database - userrequest_insert_record.php
<html><head><title>Submit a Request</title></head>
<body>
<?
$username=$POST['username'];
$department=$POST['department'];
$phoneext=$POST['phoneext'];
$location=$POST['location'];
$subject=$POST['subject'];
$equipment=$POST['equipment'];
$fdescription=$POST['fdescription'];
$uvalue=$POST['uvalue'];
$db="support";
$link = mysql_connect("localhost","user","password");
//$link = mysql_connect("localhost",$POST['username'],$POST['password']);
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link) or die("Select Error: ".mysql_error());
$result=mysql_query("INSERT INTO userrequest (Username, Department, PhoneExt, Location, Subject, Equipment, FaultDescription,Urgencyvalue, DateAndTime ) VALUES ('$username','$department','$phoneext','$location','$subject','$equipment','$fdescription','$uvalue'
, now() )")or die("Insert Error: ".mysql_error());
mysql_close($link);
print "Request added\n";
?>
<form method="POST" action="userrequest_dbase_interface.php">
<input type="submit" value="Return to Main Menu">
</form>
</body>
</html>
I am also not sure which module to put the validating code in?
Your help would be much appreciated.
Thank you.
Adi