Home Can't check if data exists in database

# Can't check if data exists in database

user4434
1#
user4434 Published in April 20, 2018, 10:50 am
 I know i post a lot of problems lately, but this one problem which i couldn't solve for about 1 week, I tried million times to check if data exists but still nothing. Searched, checked same problem but didn't get a hint. So please tell me what is wrong here. I try everything on my own but if i meet a problem i can't solve for a while. I ask here for help.  Test Title db=new MySQLi($host,$username,$password,$dbname); } public function getData(){ $query="SELECT * FROM artisan";$result=$this->db->query($query); $users=array(); if($result->num_rows>0){ while($row=$result->fetch_assoc()){ $users[]=array( "id"=>$row['id'], "username"=>$row['username'], "email"=>$row['email'] ); } }else{ echo "No results found!"; } return $users; } public function getContent(){$query="SELECT * FROM content"; $result=$this->db->query($query);$values=array(); if($result->num_rows>0){ while($row=$result->fetch_assoc()){$values[]=array( "title"=>$row['title'], "body"=>$row['body'] ); } } return $values; } public function insertData(){$title=$_POST['title'];$query="INSERT INTO content(title,body) VALUES (?,?)"; $result=$this->db->query("SELECT COUNT(*) FROM content WHERE title=$title");$stmt=$this->db->prepare($query); $stmt->bind_param("ss",$_POST['title'],$_POST['body']); if(!empty($_POST['title']) || !empty($_POST['body'])){ if($result->num_rows){ echo "User allready exists"; }else{ $stmt->execute(); } } } private function validate(){$query="SELECT title and body FROM contents"; $result=$this->db->query($query); if($result){ echo "hi"; } } } $database=new Database('localhost','root','','test');$users=$database->getData();$values=$database->getContent();$database->insertData(); ?>
"; ?> ";?>