Wednesday 17 October 2018

Handling Data in Web Forms Init: MYSQLI CRUD OOP Series

This script and codes will treat the submitted data in web forms. It will check the value of the submitted data in web forms and will instantiate a new class to execute the functions written in specific class.functions.php.

Step 4. Treat the submitted data in index.php
To capture the submitted data using Web Forms, you need to insert the following PHP codes after the <body> tag in index.php.
<?php
if (empty($_POST)===FALSE){
print_r($_POST);
$ul_name = mysql_real_escape_string($_POST['ul_name']);
$ul_desc = mysql_real_escape_string($_POST['ul_desc']);
if (empty($ul_name) || (empty($ul_desc))){
$errors[] = "Please fill in required data to process.";
}else{
//save data commands
$save = $db->save_userlevel($ul_name,$ul_desc);
if ($save==TRUE){
$success[]="Data successfully saved to database";
}else{
$errors[] = 'Unable to process data.';
}
}
}
?>
We use mysql_real_escape_string functions to treat future mysql injection issues.
The code $save = $db->save_userlevel($ul_name,$ul_desc); will call the class save_userlevel with arguments user level name and user level description.

This will prompt an error since we have not created yet the function under class.dbfunctions.php

0 comments:

Post a Comment

If possible, leave a positive comment. No hate speech or elicit comments. Thank you.