I want to add new data in my table however, i want to check if my new data name has same name with stored data name in table, if not same name we can proceed to adding new data/post.
in my database table:
=====================
ID | title | remarks
01 | orange | fruit
02 | mango | fruit
If the title column must contain unique values, put a unique index on that column. That way you can do the insert, and if the value already exists you will get a duplicate key error.
Hello Friend ! You can proceed with using mysql query. strcmp is just used to compare two strings where as mysql query is used to find out the data directly in the database
Function: to see and find if data exist in table before Insert
Table structure:
id - auto increment
artist - specific id number
title - unique title
if (isset($submit)) {
$newtitle = $_POST['title'];
$querytitle = mysql_real_escape_string($_POST['title']);
$queryalbum = mysql_real_escape_string($_POST['album']);
// col_title is name of column title in table
// indexid is the id of the table
$sqldbtitle = "SELECT * from tblmainfile WHERE col_title = '$newtitle' ";
$checktitle = mysqli_query($con, $sqldbtitle);
// This is assuming query only returns one result
$resultcheck = mysqli_fetch_array($checktitle);
// now check the value for 'title'
if ($resultcheck['col_title'] == $newtitle) {
echo "NEW TITLE IS SAME WITH EXISTING DATA";
} else {
echo "NOT THE SAME TITLE";
}
}