开发者

PHP / MySQL - update table data with session data

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜