how to avoid inserting duplicate row in php while update user profile

Date Posted:17-02-2017

This post we will explain on how to avoid duplicate mobile number update in user profile.

Assumption:

Table Name: ls_user

Column name:phone, email

Implementation:

First,pass your email id and also pass new phone number

second,run the query and check the number of rows zero mean execute next functionality otherwise return value.

<?php
$query=mysql_query("SELECT `phone`FROM `ls_users` WHERE `email` NOT IN('example@gmail.com') AND `phone` = '1234567890'");
if(mysql_num_rows($query)>0)
{
  echo "Not Possible to add this number try with another number"
}
else
{
 mysql_query("update ls_users set phone='12346543'" where email='example@gmail.com'");
}

admin

Our team has expertise across software and web development, WordPress, e-commerce, mobile applications, UI/UX, cloud and infrastructure, DevOps, CI/CD, API integration, security, testing, automation, and technical support. The team also works with AI-based software solutions, LLMs, AI workflows, AI agents, and intelligent application development to help businesses automate processes and build smarter digital solutions. We focus on developing, deploying, maintaining, and optimising secure, scalable, and reliable technology solutions while helping businesses adopt modern technologies and drive digital transformation.

Leave a Reply

Scroll to Top