When users submit a form leaving some of it's fields empty, to populate the associated empty fields of database with predefined data the following codes first check if the users are leaving the form's fields empty and then insert the predefined data in to the respective fields issuing_date reference_details and name of database through hidden form inputs.
if ((isset($_POST["submit_form"])) && ($_POST["submit_form] == "Submit")) {
$issue_date = $_POST['DEFAULT CURRENT_TIMESTAMP'];
$reference = "Not Available";
if(isset($_POST['reference_details']) && !empty($_POST['reference_details'])){
$reference = $_POST['reference_details'];
}
$drawer_name = "Not Available";
if(isset($_POST['name']) && !empty($_POST['name'])){
$drawer_name = $_POST['name'];
}
$insertSQL = sprintf("INSERT INTO table (issuing_date, reference_details, name) VALUES (%s, %s, %s)",
GetSQLValueString(trim($issue_date), "date"),
GetSQLValueString(trim($reference), "text"),
GetSQLValueString(trim($drawer_name), "text"));
and do more.......
<input type="submit" name="submit_form" id="submit" value="Submit" />
<input type="hidden" name="issuing_date" value="<?php echo "$issue_date"; ?>" />---->Line110
<input type="hidden" name="reference_details" value="<?php echo "$reference"; ?>" />---->Line111
<input type="hidden" name="name" value="<?php echo "$drawer_name"; ?>" />---->Line112
When error_log is active, the form page produces the following example of notice in the error_log whenever it is launched in the web browser.
PHP Notice: Undefined variable: issuing_date in /home/user/public_html/dir/subdir/test.php on line 110
PHP Notice: Undefined variable: reference_details in /home/user/public_html/dir/subdir/test.php on line 111
PHP Notice: Undefined variable: name in /home/user/public_html/dir/subdir/test.php on line 112
What's going wrong here? Are the hidden inputs of the form defined incorrectly?
Any idea?
$issue_dateactually being set before trying to use it in the hidden inputs?