MySQL Forums
Forum List  »  PHP

mysqli insert into table only if not exists
Posted by: jaspreet singh
Date: August 13, 2017 12:52AM

I need to insert a record into a database table only if title field doesn't match one that already exists in the DB.

<?php
include ('common/connection.php');
if(!empty($_REQUEST['submit']))
{
$title=$_REQUEST['title'];
$com=$_REQUEST['comment'];

if(!empty($_REQUEST['editid'])){
$id=$_REQUEST['editid'];
$query="update namedb set
title='$title',comment='$com' where id=$id";
header('location:all_category.php');
}else{
$query="INSERT INTO namedb (title,comment) values
('$title','$com')";
}

mysqli_query($connect,$query);
}
?>

Options: ReplyQuote


Subject
Written By
Posted
mysqli insert into table only if not exists
August 13, 2017 12:52AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.