October 17, 2018 -
Klase Notes,MYSQLI CRUD Series,PHP,Programming Notes
No comments
Save Data Functions: MYSQLI CRUD OOP Series
Step 5. Create a function that will process the data to database
Insert the following codes in the class.dbfunctions.php after
function testing() to process the data to database.
Code:
public function save_userlevel($name,$desc){
if($result = $this->dbconn->query("SELECT ulevel_name FROM tbl_userlevel WHERE ulevel_name ='$name'")){
$row_cnt = $result->num_rows;
if($row_cnt==0){
$sql = mysqli_query($this->dbconn, "INSERT INTO tbl_userlevel (ulevel_name, ulevel_desc) VALUES ('$name','$desc')") or die (mysqli_connect_error());
return $sql;
}else{
return FALSE;
}
}
}
To notify user for the status of database operation, add the code after the <table> tag.
<tr>
<td colspan="2">
<?php if (!empty($errors)): ?>
<strong>Oops!</strong><?php echo implode('', $errors); ?>
<?php endif; ?>
</td>
</tr>
<tr>
<td colspan="2"><?php if (!empty($success)): ?>
<strong>Good!</strong><?php echo implode('', $success); ?>
<?php endif; ?>
</td>
</tr>
0 comments:
Post a Comment
If possible, leave a positive comment. No hate speech or elicit comments. Thank you.