Hi Jake,
Thank you for your time in reading my post. The idea actually was taken from the sample php page that was given to me by a friend. Here's where the idea came:
Code: Select all
<?php
include("dbconnection.php");
if(isset($_POST["btnSubmit"]))
{
$id = $_POST["id"];
$date = $_POST["date"];
$status = $_POST["status"];
$territory = $_POST["territory"];
$job_title = $_POST["job_title"];
$area_of_work = $_POST["area_of_work"];
$employer = $_POST["employer"];
$department = $_POST["department"];
$location = $_POST["location"];
$date_posted = $_POST["date_posted"];
$closing_date = $_POST["closing_date"];
$gender = $_POST["gender"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$telephone = $_POST["telephone_number"];
$title = $_POST["title"];
$address_1 = $_POST["address_1"];
$address_2 = $_POST["address_2"];
$address_3 = $_POST["address_3"];
$city = $_POST["city"];
$country = $_POST["country"];
$postal_code = $_POST["postal_code"];
$website = $_POST["website"];
$email_address = $_POST["email_address"];
$comment_by_cg = $_POST["cg_comment"];
$date_emailed = $_POST["date_emailed"];
$mailing_comments= $_POST["mailing_comments"];
$telesales_comments= $_POST["telesales_comments"];
$time= $_POST["time"];
$query = "INSERT INTO records (date, status, territory, job_title, area_of_work, employer, department, location, date_posted, closing_date, gender, first_name, last_name, telephone_number, title, address_1, address_2, address_3, city, country, postal_code, website, email_address, cg_comment, date_emailed, mailing_comments, telesales_comments, time) VALUES ('".$date."','".$status."','".$territory."', '".$job_title."', '".$area_of_work."', '".$employer."', '".$department."', '".$location."', '".$date_posted."', '".$closing_date."', '".$gender."', '".$first_name."', '".$last_name."', '".$telephone_number."', '".$title."', '".$address_1."', '".$address_2."', '".$address_3."', '".$city."', '".$country."', '".$postal_code."', '".$website."', '".$email_address."', '".$cg_comment."', '".$date_emailed."', '".$mailing_comments."', '".$telesales_comments."', '".$time."')";
mysql_query($query) or die(mysql_error());
echo "<script>
alert('You have successfully added a record');
window.location = 'add_client.php';
</script>";
}
?>
Due to the page requirements, I needed to modify his code (I do apologize if I am not doing it very good, I am a real noob in the industry). What happens is, I need to reload the page should the user left a field blank. However, all my attempts leave me from just displaying a message and clicking the back button to return from the page. So when I try to browse through his code, I modified it by applying the if statement. It is indeed very long, but for a newbie like me, that's the solution I found since my friend didn't want me to be spoon fed.
Any suggestions? The whole code is here:
Code: Select all
<link href="add_client.css" rel="stylesheet" type="text/css">
<script type="text/javascript">
function alpha(e) {
var k;
document.all ? k = e.keyCode : k = e.which;
return ((k > 64 && k < 91) || (k > 96 && k < 123) || k == 8 || k == 32);
}
function numbersonly(myfield, e, dec)
{
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == "."))
{
myfield.form.elements[dec].focus();
return false;
}
else
return false;
}
function dtval(d,e) {
var pK = e ? e.which : window.event.keyCode;
if (pK == 8) {d.value = substr(0,d.value.length-1); return;}
var dt = d.value;
var da = dt.split('/');
for (var a = 0; a < da.length; a++) {if (da[a] != +da[a]) da[a] = da[a].substr(0,da[a].length-1);}
if (da[0] > 31) {da[1] = da[0].substr(da[0].length-1,1);da[0] = '0'+da[0].substr(0,da[0].length-1);}
if (da[1] > 12) {da[2] = da[1].substr(da[1].length-1,1);da[1] = '0'+da[1].substr(0,da[1].length-1);}
if (da[2] > 9999) da[1] = da[2].substr(0,da[2].length-1);
dt = da.join('/');
if (dt.length == 2 || dt.length == 5) dt += '/';
d.value = dt;
}
</script>
<?php
include("dbconnection.php");
if(isset($_POST["btnSubmit"]))
{
$id = $_POST["id"];
$date = $_POST["date"];
$status = $_POST["status"];
$territory = $_POST["territory"];
$job_title = $_POST["job_title"];
$area_of_work = $_POST["area_of_work"];
$employer = $_POST["employer"];
$department = $_POST["department"];
$location = $_POST["location"];
$date_posted = $_POST["date_posted"];
$closing_date = $_POST["closing_date"];
$gender = $_POST["gender"];
$first_name = $_POST["first_name"];
$last_name = $_POST["last_name"];
$telephone = $_POST["telephone_number"];
$title = $_POST["title"];
$address_1 = $_POST["address_1"];
$address_2 = $_POST["address_2"];
$address_3 = $_POST["address_3"];
$city = $_POST["city"];
$country = $_POST["country"];
$postal_code = $_POST["postal_code"];
$website = $_POST["website"];
$email_address = $_POST["email_address"];
$comment_by_cg = $_POST["cg_comment"];
$date_emailed = $_POST["date_emailed"];
$mailing_comments= $_POST["mailing_comments"];
$telesales_comments= $_POST["telesales_comments"];
$time= $_POST["time"];
if (empty($location)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($area_of_work)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($job_title)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($employer)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($department)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($date_posted)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($closing_date)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($first_name)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($last_name)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($title)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($address_1)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($address_2)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
if (empty($address_3)) {
echo "<script>
alert('Please fill out necessary fields');
window.location = 'add_client.php';
</script>";
}
else
$query = "INSERT INTO records (date, status, territory, job_title, area_of_work, employer, department, location, date_posted, closing_date, gender, first_name, last_name, telephone_number, title, address_1, address_2, address_3, city, country, postal_code, website, email_address, cg_comment, date_emailed, mailing_comments, telesales_comments, time) VALUES ('".$date."','".$status."','".$territory."', '".$job_title."', '".$area_of_work."', '".$employer."', '".$department."', '".$location."', '".$date_posted."', '".$closing_date."', '".$gender."', '".$first_name."', '".$last_name."', '".$telephone_number."', '".$title."', '".$address_1."', '".$address_2."', '".$address_3."', '".$city."', '".$country."', '".$postal_code."', '".$website."', '".$email_address."', '".$cg_comment."', '".$date_emailed."', '".$mailing_comments."', '".$telesales_comments."', '".$time."')";
mysql_query($query) or die(mysql_error());
echo "<script>
alert('You have successfully added a record');
window.location = 'add_client.php';
</script>";
}
?>
<table width="760" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="199" align="center" valign="top"><a href="login.html"><img src="image.gif" alt="" width="152" height="58" border="0" /></a></td>
<td width="176" align="right" valign="bottom"><a href="main.php"><img src="Home.jpg" width="104" height="20" border="0"/></a></td>
<td width="130" align="right" valign="bottom"><a href="view_client.php"><img src="View.jpg" width="104" height="20" border="0"/></a></td>
<td width="146" align="right" valign="bottom"><img src="Add.jpg" width="104" height="20" border="0"/></td>
<td width="109" align="right" valign="bottom"> </td>
</tr>
</table></td>
</tr>
<tr>
<td><table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="3" bgcolor="#1B1C78"><img src="images/topspacerblue.gif" alt="" width="1" height="3" /></td>
<td width="560" bgcolor="#0076CC"><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /></td>
</tr>
</table></td>
</tr>
<tr>
<td height="526" align="center" valign="top" bgcolor="#F3FAFE"><p> </p>
<form name="form" method="post" action="add_client.php">
<table width="679" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="160" height="26" align="left" valign="middle" scope="col">Date and Time</td>
<td width="160" height="26" align="center" valign="middle" scope="col">
<?php
$date = date("d/m/y");
print date("d/m/y |", time())
?>
<?php
print date("h:i a", time())
?></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td height="26" colspan="2" align="left" valign="middle" scope="col">Status</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col">NEW RECORD</td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Territory</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><select name="territory" width="230" style="width: 143px" id="territory">
<option selected="selected" disabled="disabled">Select Territory</option>
<option>Territory 1</option>
<option>Territory 2</option>
<option>Territory 3</option>
<option>Territory 4</option>
<option>Territory 5</option>
<option>Territory 6</option>
<option>Territory 7</option>
<option>Territory 8</option>
<option>Territory 9</option>
<option>Territory 10</option>
</select></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td colspan="2" align="left" valign="middle" scope="col">Location </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"><input name="location" type="text" id="location" onkeypress="return alpha(event)"/></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Area of Work</td>
<td width="160" height="26" align="center" valign="middle" scope="col"><input name="area_of_work" type="text" id="area_of_work" onkeypress="return alpha(event)"/></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td colspan="2" align="left" valign="middle" scope="col">Job Title</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="job_title" type="text" id="job_title" onkeypress="return alpha(event)"/></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Employer</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="employer" type="text" id="employer" onkeypress="return alpha(event)"/></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td colspan="2" align="left" valign="middle" scope="col">Department</td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"><input name="department" type="text" id="department" onkeypress="return alpha(event)"/></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Date Posted<br />
(dd/mm/yyyy)</td>
<td width="160" height="26" align="center" valign="middle" scope="col"><input name="date_posted" type="text" id="date_posted" onkeyup="dtval(this,event)" maxlength="10"/></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td colspan="2" align="left" valign="middle" scope="col">Closing Date<br />
(dd/mm/yyyy)</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="closing_date" type="text" id="closing_date" onkeyup="dtval(this,event)" maxlength="10"/></td>
</tr>
<tr>
<td width="160" height="27" align="left" valign="middle" scope="col"> </td>
<td width="160" height="27" align="center" valign="middle" scope="col"> </td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col"> </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"> </td>
</tr>
<tr>
<td width="160" height="26" align="left" valign="middle" scope="col">First Name</td>
<td width="160" height="26" align="center" valign="middle" scope="col"><input name="first_name" type="text" id="first_name" onkeypress="return alpha(event)"/></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td height="26" colspan="2" align="left" valign="middle" scope="col">Last Name</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="last_name" type="text" id="last_name" onkeypress="return alpha(event)"/></td>
</tr>
<tr>
<td width="160" height="27" align="left" valign="middle" scope="col">Title</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="title" type="text" id="title" onkeypress="return alpha(event)"/></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col">Telephone Number</td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"><input name="telephone_number" type="text" id="telephone_number" onKeyPress="return numbersonly(this, event)"/></td>
</tr>
<tr>
<td width="160" height="27" align="left" valign="middle" scope="col">Address 1</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="address_1" type="text" id="address_1" /></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col">Address 2</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="address_2" type="text" id="address_2" /></td>
</tr>
<tr>
<td width="160" height="26" align="left" valign="middle" scope="col">Address 3</td>
<td width="160" height="26" align="center" valign="middle" scope="col"><input name="address_3" type="text" id="address_3" /></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td height="26" colspan="2" align="left" valign="middle" scope="col">City</td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"><input name="city" type="text" id="city" onkeypress="return alpha(event)"/></td>
</tr>
<tr>
<td width="160" height="27" align="left" valign="middle" scope="col">Country</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="country" type="text" id="country" onkeypress="return alpha(event)"/></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col">Postal Code</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="postal_code" type="text" id="postal_code" onKeyPress="return numbersonly(this, event)"/></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col"> </td>
<td width="160" height="26" align="center" valign="middle" scope="col"> </td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td height="26" colspan="2" align="left" valign="middle" scope="col"> </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"> </td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Website</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="website" type="text" id="website" /></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col">Email Address</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="email_address" type="text" id="email_address" /></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col"> </td>
<td width="160" height="27" align="center" valign="middle" scope="col"> </td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="left" valign="middle" scope="col"> </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"> </td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">CG Comment</td>
<td width="160" height="26" align="center" valign="middle" scope="col"><input name="cg_comment" type="text" id="cg_comment" /></td>
<td width="39" height="26" align="left" valign="top" scope="col"> </td>
<td height="26" colspan="2" align="left" valign="middle" scope="col">Date Emailed<br />
(dd/mm/yyyy)</td>
<td height="26" colspan="2" align="center" valign="middle" scope="col"><input name="date_emailed" type="text" id="date_emailed" onkeyup="dtval(this,event)" maxlength="10"/></td>
</tr>
<tr>
<td width="160" align="left" valign="middle" scope="col">Mailing Comment</td>
<td width="160" height="27" align="center" valign="middle" scope="col"><input name="mailing_comment" type="text" id="mailing_comment" /></td>
<td width="39" height="27" align="left" valign="top" scope="col"> </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"> </td>
<td height="27" colspan="2" align="center" valign="middle" scope="col"> </td>
</tr>
<tr>
<td align="left" valign="middle" scope="col">Telesales Comment</td>
<td height="27" align="center" valign="middle" scope="col"><input name="telesales_comment" type="text" id="telesales_comment" /></td>
<td height="27" align="left" valign="middle" scope="col"> </td>
<td width="49" height="27" align="center" valign="middle" scope="col"><a href="add_client.php"><img src="Delete.png" width="27" height="27" border="0"/></a></td>
<td width="111" align="left" valign="middle" scope="col">Clear Fields</td>
<td width="53" height="27" align="center" valign="middle" scope="col">
<input type="image" src="Add.png" height="27" width="27" name="btnSubmit" id="btnSubmit" value="Add Record"/></td>
<td width="107" align="left" valign="middle" scope="col">Add Record</td>
</tr>
<tr>
<td height="27" colspan="7" align="left" valign="middle" scope="col"><input name="status" type="text" width="10" id="status" style="visibility:hidden" value="New Record"/>
<input name="date" type="text" width="10" id="date" style="visibility:hidden" value="<?php $date = date("d/m/y");
print date("d/m/y |", time())
?>"/>
<input name="time" type="text" width="10" id="time" style="visibility:hidden" value="<?php print date("h:i a", time())?>"/></td>
</tr>
</table>
</form></p></td>
</tr>
<tr>
<td height="38"><table width="760" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="200" height="35" align="center" bgcolor="#1B1C78" class=white><img src="images/topspacerblue.gif" alt="" width="1" height="3" /> <a href="disclaimer.html"><font color="#FFFFFF">Legal Disclaimer</font></a> </td>
<td width="560" align="center" bgcolor="#0076CC" class=white><img src="images/topspacerlblue.gif" alt="" width="1" height="3" /> Copyright © 2006 - 2010 Limited. All rights reserved.
</td>
</tr>
</table></td>
</tr>
</table>