Hi, i'm a complete newbie to php and have been relying on premade codes so far to create what i need. I've tried all these sort of templates for form validation but none seem to work, example.
What I want to add to my form is some sort of required field validation for certain fields, please note that some of these fields are option boxes, plain text entry boxes and option list boxes. What I ideally want is some sort of message that either comes up on the same page or as a pop-up box saying which boxes need t be filled in before the form is submitted.
Any help with this would be greatly appreciated, as i'm completely stuck on this.
I'm making a data submission form using the following code to send data from the form to the sql database:
<?php
if ($post == "yes") {
//THEN WE ARE ADDING A NEW RECORD SUBMITTED FROM THE FORM
//REPLACE THE FIELD CONTENTS SO THEY DON'T MESS UP YOUR QUERY
/-- SECTION: 9994SQL --/
$sql = "INSERT INTO term (
id,
contract_hours,
FTE,
salary_band,
staff_type,
TPF,
TNPF,
RPF,
RNPF,
RPF_R11,
RPF_R12,
RNPF_R21,
RPF_R13,
RNPF_R22,
RPF_R14,
RNPF_R23,
RNPF_R24,
O,
O1,
ST,
SR,
SO,
SG
$addl_insert_crit ) VALUES ( '$id',
'$contract_hours',
'$FTE',
'$salary_band',
'$staff_type',
'$TPF',
'$TNPF',
'$RPF',
'$RNPF',
'$RPF_R11',
'$RPF_R12',
'$RNPF_R21',
'$RPF_R13',
'$RNPF_R22',
'$RPF_R14',
'$RNPF_R23',
'$RNPF_R24',
'$O',
'$O1',
'$ST',
'$SR',
'$SO',
'$SG'
$addl_insert_values )";
if ($sql_debug_mode==1) { echo "<BR>SQL: $sql<BR>"; }
$result = mysql_query($sql,db());
if ($result == 1) {
echo "Record Inserted";
} else {
echo "Error inserting record (9994SQL)";
}
//** END INSERT SQL **
} //END IF POST = YES FOR ADDING NEW RECORDS
if (!$post) {
//THEN WE ARE ENTERING A NEW RECORD
//** BEGIN ADD NEW FORM**
/-- SECTION: 9994FORM --/
?>[/COLOR]
and this at the bottom of the page after all the html form layout, etc:
<?php
} //END if post=""
//** END ADD NEW ENTRY FORM**
/*---------------------------------------------------------------
FUNCTION: db()
DESCRIPTION: CREATES DB CONNECTION OBJECT FOR KNEBEL.NET
PHP CODE GENERATOR CODE.
INPUTS: NONE
RETURNS: DATABASE CONNECTION OBJECT
GLOBAL VARIABLES: NONE
FUNCTIONS CALLED: NONE
CALLED BY:
AUTHOR: KNEBEL
MODIFICATIONS:
MM/DD/YY - CREATED FUNCTION (KNEBEL.NET)
NOTES:
----------------------------------------------------------------*/
function db()
{
$dbuser = "";
$dbserver = "";
$dbpass = "";
$dbname = "";
//CONNECTION STRING
$db_conn = mysql_connect($dbserver, $dbuser, $dbpass)
or die ("UNABLE TO CONNECT TO DATABASE");
mysql_select_db($dbname)
or die ("UNABLE TO SELECT DATABASE");
return $db_conn;
}//end function db
?>[/COLOR]