I'm working on a custom CMS using PHP OOP. Basically I have made a class that can add a new row to db.
My Class:
<?php
class Navigation
{
private $db;
public function __construct()
{
$this->db = new Connection();
$this->db = $this->db->dbConnect();
}
public function NewMenu($menu_name,$menu_numbers)
{
if (!empty($menu_name) && !empty($menu_numbers)) {
$sql = "INSERT INTO menu_nav "
. "(menu_name, menu_items) VALUES (?, ?)";
$ins = $this->db->prepare($sql);
$ins->bindParam(1,$menu_name);
$ins->bindParam(2,$menu_numbers);
$ins->execute();
} else {
header("Location: maint/php/includes/errors/009.php");
exit();
}
}
}
This class works fine but the problem is that I don't know how to check if the menu_name
exists already in the table or not. And if yes ,it should receive the error message that "Data can not be inserted to db" for example. So if you know how to do this feature in PHP OOP ,please let me know cause I really need it.