if statement for Form field and database insert
Posted: Fri Mar 05, 2010 11:55 am
Here is a cut down version of what I'm doing... in the guts of my coding, I present a form field that is only active if a checkbox is checked (ie; Alternate Contact information)
It then enables a field called "wo_fname", that is otherwise disabled:
Then, upon submission, I am uploading that information to MySQL database:
(note that MM_insert is a hidden value submitted with the form submission)
Here's where I need help... if the box is NOT checked, and the form is submitted, I want to replace wo_fname with a variable that I have already successfully pulled into my code, and that I have already assigned to be wo_fname... it is being over-written, however, by the NULL value and the form is not submitting. What I need to do, is to write an If statement so that if the form field is NULL, then $wo_fname does not change to a NULL value.
Code: Select all
<input type="checkbox" name="alternate_contact" id="alternate_contact" onClick="document.getElementById('wo_fname').disabled=(this.checked)?0:1;>Code: Select all
<input id="element_10_1" name= "wo_fname" class="element text" maxlength="255" size="14" value="" disabled/>Code: Select all
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO work_orders (wo_fname) VALUES (%s)",
GetSQLValueString($_POST['wo_fname'], "int");Here's where I need help... if the box is NOT checked, and the form is submitted, I want to replace wo_fname with a variable that I have already successfully pulled into my code, and that I have already assigned to be wo_fname... it is being over-written, however, by the NULL value and the form is not submitting. What I need to do, is to write an If statement so that if the form field is NULL, then $wo_fname does not change to a NULL value.