السلام عليكم ورحمة الله وبركاته ..
الإخوة والأخوات الأكارم ..
سؤالي :
عندي صفحة فيها مقال وعليه تعليقات الزوار .. كل شيء ماشي تمام معاي ..
لكن ظهر معي خلل!
عندما أحدث الصفحة تضاف البيانات مرة أخرى إلى قاعدة البيانات!
كيف أمنع إضافة البيانات عند تحديث الصفحة؟
علما أن كود الإضافة بنفس صفحة العرض ..
صفحة عرض البيانات 'كود الإضافة ' :
if(isset($_POST['send'])){
require_once './includes/valid-norm-form.inc.php';
require_once './includes/setData.inc.php';
require_once './includes/customValid.php';
$valid = new customValid();
$valid->check_empty();
$valid->min_length('name', 3);
$valid->max_length('name', 15);
$valid->min_length('content', 10);
$valid->max_length('content', 500);
$valid->check_email('email');
if(!$valid->get_errors()){
$set = new setData(strip_tags($_POST['content']), strip_tags($_GET['id'])
, strip_tags($_POST['name']), strip_tags($_POST['email']));
echo '<b style="color:red; font-family:tahoma;">'."شكرا على تواصلك ، سيتم نشر التعليق بعد موافقة المشرف".'</b>';
}
else{
echo '<B style="color:red;">ERRORS ! :</B>';
$valid->print_errors();
}}فئة الاتصال بقاعدة البيانات :
class Connection_db {
private $host = 'localhost';
private $user = 'root';
private $pass = 'root';
private $db = 'cofee';
private $con ;
public function __construct() {
$this->p_connection();
}
protected function p_connection(){
$this->con = new mysqli($this->host, $this->user, $this->pass, $this->db)
or die(mysqli_error()) or die(mysqli_connect_error());
$this->con->set_charset("utf8");
}
public function get_connection(){
return $this->con;
}
}فئة الاستعلام :
require 'conn.inc.php';
class setData extends Connection_db{
private $_comment ;
private $_content_id;
private $_email;
private $_name;
public function __construct($coment,$content_id,$name,$email) {
parent::__construct();
$this->_comment = $coment;
$this->_content_id= $content_id;
$this->_name= $name;
$this->_email = $email;
$this->insert_comment();
}
private function insert_comment(){
$getCon = parent::get_connection();
$sql = 'insert into commentes (p_name,email,content_id,content_of_comment) values('.
"'".$this->_name."','".$this->_email."',".$this->_content_id.",'".$this->_comment."')";
$result = $getCon->query($sql) or die(mysqli_error());
if(!$result){
echo "ERROR!".mysqli_error();
}
}
}هل من اقتراحات لحل الإشكال؟
لكم مني أعطر التحايا.