开发者

PHP / MySQL - update table data with session data

开发者 https://www.devze.com 2023-03-27 23:34 出处:网络
How to update table data with data stored in session? I have following code but it is not working(INSERTING INTO DB not working exactly). Please not that this is just part of the code. Session value

How to update table data with data stored in session?

I have following code but it is not working(INSERTING INTO DB not working exactly). Please not that this is just part of the code. Session value are being saved correctly. I have a problem with saving them though.

If I have made silly mistake - apologies - I'm newby.

    $loggedTime = $_SESSION['loggedtime'];
    $thisUser = $_SESSION['usr'];

    $result = mysql_query("UPDATE 'admin' SET dt = $loggedTime WHERE $thisuser");
    if($result) {
         echo "success"; 
    } else { 
        echo "no success";开发者_运维问答 
    }


"UPDATE `admin` SET `dt` = '$loggedTime' WHERE user = '$thisUser'"

Don't use single quotes around column/table names. Single/double quotes indicate string literals. Use back ticks around table/column names, if you have to (i.e. reserved word). Also, have a look at Bobby Tables. Furthermore, you need a column in the where clause.


UPDATE 'admin'

replace the single quote

UPDATE admin SET ...

Understand lots of people tend to use back-tick to quote the table, column name ... i don't think is necessary

just take a look on the mysql docs
THEY never do that


Try to explicitly name the column in your WHERE clause and surround variables with single quotes.

"UPDATE `admin` SET dt = '$loggedTime' WHERE user = '$thisuser'"


Theres a problem with your SQL query.

UPDATE 'admin' SET dt = $loggedTime WHERE $thisuser

The where clause isn't specifying any condition try:

UPDATE 'admin' SET dt = '$loggedTime' WHERE userField = $thisuser

replacing 'userField' with a relavent field name that you would like to condition for.

0

精彩评论

暂无评论...
验证码 换一张
取 消