Updating Database Elements

Codes here !

Moderators: egami, macek, gesf

Post Reply
TommyD
New php-forum User
New php-forum User
Posts: 1
Joined: Wed Jun 21, 2017 6:31 am

Wed Jun 21, 2017 6:34 am

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')");
}

chorn
php-forum Active User
php-forum Active User
Posts: 405
Joined: Fri Apr 01, 2016 2:18 am

Thu Jun 22, 2017 1:39 am

you do not run the query like the insert.

Post Reply