PHP MySQL Check if row exists

dinkode.dk

Im building a login for our employees and now I'm creating the validation for each input fields. If I have a table named pages and inside that table I've got a column field named title. As an example I've created a dummy title My new title.

I've created a function that let's our users create new pages, and I want to be able to check if the title already exists in our database.

For example, if the user types in My new title and submits the form, then he gets an error message with the following text: Sorry, your title already exists

I know I haven't provided much information here, but I'm from scratch on this one. I know how to check if a number is the same, or if two input field/db rows doesn't match each other. It may be an easy one, but I really can't figure it out.

I would be very grateful if you had a simple solution to this. Continue a wonderful day :)

Nishant Kumar

You can achieve this by these way:

  1. Add unique constrain to column title
  2. Using INSERT ... ON DUPLICATE KEY UPDATE statement
  3. Do a query before insert on that column value if it return more than 0 result than it exist. like : SELECT * FROM pages WHERE title = 'new_title';

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

check if specific row exists mysql

From Dev

MySQL check if row with category exists

From Dev

PHP check if value exists in MySQL

From Dev

PHP - Check if row exists before inserting

From Dev

PHP MySql - Confirm row value exists

From Dev

How to check if value exists in MySQL Database in PHP?

From Dev

PHP MySQL Query to check if record exists or not

From Dev

php check if mysql select exists or empty

From Dev

php check if mysql select exists or empty

From Dev

check username and email already exists in php mysql

From Dev

How to check if a row exists in MySQL? (i.e. check if an email exists in MySQL)

From Dev

Check if row exists in DataTable?

From Dev

Check if row exists, Laravel

From Dev

Check if row exists in database

From Dev

Check if row exists in an xml

From Dev

Check if row exists in database

From Dev

Check row if value exists

From Dev

if statement to check if mysql row exists, then selecting next query

From Dev

php check if row in database exists returns always true

From Dev

Check for empty row from mysql in PHP

From Dev

PHP MYSQL check if row data is the same as

From Dev

If exists, duplicate row in MySQL

From Dev

Check if a column exists in mysql

From Dev

IF row exists THEN delete row in mysql

From Dev

php check if input value exists in mysql (related with performance)

From Dev

PHP How to check if a string already exists in a MySQL table

From Dev

check if username exists in real-time through AJAX in php with mysql

From Dev

Check if session exists in php

From Dev

PHP check if value exists