# Updating Database Values

**URL:** <https://www.phphelp.com/t/updating-database-values/25932>\
**Category:** MySQL database\
**Created:** [June 21, 2017, 2:44pm UTC](https://www.phphelp.com/t/updating-database-values/25932 "2017-06-21T14:44:18Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jakeZ200](https://www.phphelp.com/letter_avatar_proxy/v4/letter/j/a8b319/32.png) [@jakeZ200](https://www.phphelp.com/u/jakeZ200)\
**Post date:** [June 21, 2017, 2:44pm UTC](https://www.phphelp.com/t/updating-database-values/25932/1 "2017-06-21T14:44:18Z")

</div>

I’m working on a small project that uses php and an sql database. The database contains three elements - names, scores, and messages. Three variables are sent to the php file, it checks all the database ‘name’ elements for a match. If there is a match, the corresponding score and message values are replaced. If the name doesn’t exist in the database - the name, score, and comment elements are all added in a new row. This is my non working code. I can add a new entry, but my conditional statement, and UPDATE code isn’t working. I think it’s close. Any help is appreciated.

$teamName = $\_POST[‘name’];  
$teamScore = $\_POST[‘score’];  
$teamMessage = $\_POST[‘message’];

if(record\_exists(‘name’, $teamName))  
{  
$sql = “UPDATE scoring SET score=’$teamScore’, comment=’$teamMessage’ WHERE name=’$teamName’”;  
}  
else  
{  
$sql = mysqli\_query($con, “INSERT INTO scoring (name, score, comment)VALUES(’$teamName’,’$teamScore’,’$teamMessage’)”);  
}

---

<div class="post-metadata">

**Author:** ![benanamen](https://www.phphelp.com/user_avatar/www.phphelp.com/benanamen/32/287_2.png) [@benanamen](https://www.phphelp.com/u/benanamen)\
**Post date:** [June 21, 2017, 4:32pm UTC](https://www.phphelp.com/t/updating-database-values/25932/2 "2017-06-21T16:32:46Z")

</div>

Set a unique index on the column(s) and then do a single INSERT IGNORE query.
