dates

crazyal

Maddy
Hi all
So I have this piece of script

whereby the first line gets the date in a formatted way

however the date iin the $query always picks up what is already in the DB rather than the current date. What am I doing wrong? I did an echo of the $query and it shows the old date.

$f_today = date('Y-m-d H:i:s'); <-----------------
$query=mysqli_query($conn, "UPDATE Avatar SET
Avatar.SL_LEG_NAME = '$SL_LEG_NAME',
Avatar.CUR_DIF_LVL = '$CUR_DIF_LVL',
Avatar.TIMER_INCEPT = `$TIMER_INCEPT',
Avatar.TIMER_DIF_LVL_1 = '$TIMER_DIF_LVL_1',
Avatar.TIMER_DIF_LVL_2 = '$TIMER_DIF_LVL_2',
Avatar.TIMER_DIF_LVL_3 = '$TIMER_DIF_LVL_3',
Avatar.TIMER_DIF_LVL_4 = '$TIMER_DIF_LVL_4',
Avatar.TIMER_DIF_LVL_5 = '$TIMER_DIF_LVL_5',
Avatar.TIMER_TODAY = '$TIMER_TODAY',
Avatar.LAST_LOGON = '$f_today', <-----------------
Avatar.EXPERIENCE = '$EXPERIENCE',
Avatar.LIVRES_IN = '$LIVRES_IN',
Avatar.LIVRES_OUT = '$LIVRES_OUT',
Avatar.LINDEN_IN = '$LINDEN_IN',
WHERE Avatar.UUID = '$SL_UUID'");
 
In your SQL query, you have used backticks () around $TIMER_INCEPT`, which should ideally be single quotes ('') or none if it's a direct value. Backticks are used in SQL to denote identifiers (like table or column names), not string values.

PHP:
Avatar.TIMER_INCEPT = `$TIMER_INCEPT',

Echo Debugging: Immediately after setting $f_today, echo its value to ensure it contains the expected current date and time.


PHP:
$f_today = date('Y-m-d H:i:s');
echo "Current date: $f_today<br>";

After addressing the backtick issue and verifying the date handling, your corrected SQL query should look like this:

PHP:
$query = mysqli_query($conn, "UPDATE Avatar SET
    Avatar.SL_LEG_NAME = '$SL_LEG_NAME',
    Avatar.CUR_DIF_LVL = '$CUR_DIF_LVL',
    Avatar.TIMER_INCEPT = '$TIMER_INCEPT',
    Avatar.TIMER_DIF_LVL_1 = '$TIMER_DIF_LVL_1',
    Avatar.TIMER_DIF_LVL_2 = '$TIMER_DIF_LVL_2',
    Avatar.TIMER_DIF_LVL_3 = '$TIMER_DIF_LVL_3',
    Avatar.TIMER_DIF_LVL_4 = '$TIMER_DIF_LVL_4',
    Avatar.TIMER_DIF_LVL_5 = '$TIMER_DIF_LVL_5',
    Avatar.TIMER_TODAY = '$TIMER_TODAY',
    Avatar.LAST_LOGON = '$f_today',
    Avatar.EXPERIENCE = '$EXPERIENCE',
    Avatar.LIVRES_IN = '$LIVRES_IN',
    Avatar.LIVRES_OUT = '$LIVRES_OUT',
    Avatar.LINDEN_IN = '$LINDEN_IN'
WHERE Avatar.UUID = '$SL_UUID'");

Make sure $SL_UUID and all other variables used in the query are correctly populated and sanitized to prevent SQL injection vulnerabilities.

Best Regard
Danish Hafeez | QA Assistant
ICTInnovations
 
OK I am utterly dumbfounded. Other than the typo I made using a ` (backstick) instead of ' (quote), I cannot find any differences. Only difference I see is the spacing I did to make it easier to read (does not show in the post here) where I tabbed the variables on the right over to align for viewing. Are you telling e PHP is so anal it doesn't allow formatting of lines in terms of spacing things out for easier in-editor viewing? SERIOUSLY?
LOL. Well whatever you did, IT WORKS and I have NO CLUE why, LOL. But thank you so much!!

Oh incidentally, I had spotted the back stick typo after I had posted my original message and corrected it but it still didn't work. So ya, I still don't see any differences other than the inline formatting :)))
 
ALRIGHTY! I just found the difference and I feel like an idiot. There was one extra comma JUST before the WHERE statement. I took it off and the script worked
 
Back
Top