Can't get score to update with this mysql statement

user2284703

I'm guessing that I'm just a little rusty or something because it seems like this should be working. Am I missing something here...

Here is the code I am trying to use...

<?php 
echo dbConn();
$existing_time = mysql_result(mysql_query("SELECT p_time FROM scores WHERE p_uid=$uid"), 0);
$existing_category = mysql_result(mysql_query("SELECT p_cat FROM scores WHERE p_uid=$uid AND p_cat=$pieces"), 0);

if ($existing_category == "") {
mysql_query(
          "INSERT INTO scores VALUES (
          '',
          '$uid',
          '$pusername', 
          '$time',
          '$pieces'
          )");
} elseif ($existing_time <= $time) {
    echo "No Change!  Old Score Was Better (Lower)";
} elseif ($existing_time > $time) {
    mysql_query("UPDATE scores SET p_time = " . $time . " WHERE p_uid = " . $uid . " AND p_cat = " . $pieces . "");
};
?>

Now... Here is what I am trying to do...

I am collecting info from the database where the users username AND category match. If the category for that user does not exist, it inserts the latest score. (This much works.)

Then, if the category does exist but the old score is better, it just does nothing. (This part works too)...

However, what I can't seem to do is get it to update the last score, if the current score is better (lower score, since this is a time based game.) It doesn't update the score.

I am trying it this way: By updating a row in "scores" where the USERNAME and the CATEGORY match at the same time.

Please note... where it says "pieces". this is a category. Where it says "time", this is a score. The score is returned as 00:00:00 for hours minutes and seconds.

EXAMPLE: (in parentheses is the database row name)

id (ID) = just KEY id in sequencial order

user id (p_uid) = 123456789

username (p_username) = somename

score (p_time) = 00:01:03

category (p_cat) = 10

Newbie

Change you update statement to:

mysql_query("UPDATE scores SET p_time = '" . $time . "' WHERE p_uid = " . $uid . " AND p_cat = " . $pieces . "");

You have missed quotes in the update statement around $time.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Can't get php to update mysql

From Dev

can't get time data via $_POST['attime']) to UPDATE mysql

From Dev

mysql injection inside update statement by GET or POST

From Dev

Can't update data via select statement

From Dev

MYSQL statement works when entered in framework, can't get framework to work with function when saved mysql

From Dev

MYSQL statement works when entered in framework, can't get framework to work with function when saved mysql

From Dev

I can't get update

From Dev

Update User Score if exists in MYSQL

From Dev

JQuery if statement can't get attr value

From Dev

Can't get simple if statement to work properly

From Dev

Can't get a prepared statement to print in php

From Java

How can I get my print statement to work to where it prints the average score and the correlating letter grade?

From Dev

MySQL Error: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

From Dev

Can't get MySQL working

From Dev

How Can i write update statement in mysql with select query?

From Dev

PHP form MySql EDIT / UPDATE - Can't get form to populate with data

From Dev

MYSQL: SELECT and UPDATE in the same statement won't work - 1064 error

From Dev

MySQL `UPDATE` statement with an `IF` condition

From Dev

Update MySQL statement not firing

From Dev

Mysql update query with IF statement

From Dev

mysql statement to update dynamically

From Dev

MySQL UPDATE, IF, INSERT INTO statement

From Dev

can't update date value MySQL python

From Dev

Can't update data from MySQL database

From Dev

Can't update data in mysql from php

From Dev

PHP & MySql: can't update database

From Dev

Why can't I Update mysql table?

From Dev

Can't update array value in mysql

From Dev

Can't figure out WHY this UPDATE statement is running

Related Related

  1. 1

    Can't get php to update mysql

  2. 2

    can't get time data via $_POST['attime']) to UPDATE mysql

  3. 3

    mysql injection inside update statement by GET or POST

  4. 4

    Can't update data via select statement

  5. 5

    MYSQL statement works when entered in framework, can't get framework to work with function when saved mysql

  6. 6

    MYSQL statement works when entered in framework, can't get framework to work with function when saved mysql

  7. 7

    I can't get update

  8. 8

    Update User Score if exists in MYSQL

  9. 9

    JQuery if statement can't get attr value

  10. 10

    Can't get simple if statement to work properly

  11. 11

    Can't get a prepared statement to print in php

  12. 12

    How can I get my print statement to work to where it prints the average score and the correlating letter grade?

  13. 13

    MySQL Error: Can't update table 'tbl' in stored function/trigger because it is already used by statement which invoked this stored function/trigger

  14. 14

    Can't get MySQL working

  15. 15

    How Can i write update statement in mysql with select query?

  16. 16

    PHP form MySql EDIT / UPDATE - Can't get form to populate with data

  17. 17

    MYSQL: SELECT and UPDATE in the same statement won't work - 1064 error

  18. 18

    MySQL `UPDATE` statement with an `IF` condition

  19. 19

    Update MySQL statement not firing

  20. 20

    Mysql update query with IF statement

  21. 21

    mysql statement to update dynamically

  22. 22

    MySQL UPDATE, IF, INSERT INTO statement

  23. 23

    can't update date value MySQL python

  24. 24

    Can't update data from MySQL database

  25. 25

    Can't update data in mysql from php

  26. 26

    PHP & MySql: can't update database

  27. 27

    Why can't I Update mysql table?

  28. 28

    Can't update array value in mysql

  29. 29

    Can't figure out WHY this UPDATE statement is running

HotTag

Archive