Sir, my table look like this

aa.png

I am using this query to insert data

         $query = "INSERT INTO history(user, login, logout, duration, user_ip, user_lo)
          VALUES ('".$muser."','".($date('Y-m-d H:i:s')."','".($date('Y-m-d H:i:s')."',1,'".$_SERVER['SERVER_ADDR']."','myplace')";

But it says:
Parse error: syntax error, unexpected ';' in C:\wamp\www......

I am unable to know what is wrong in my query, please help

Hi,

look I will not fix that query as it would be wrong in any case. Use prepared statements.

Example with PDO:

$query = "INSERT INTO `history` (`user`, `login`, `logout`, `duration`, `user_ip`, `user_lo`) VALUES (:user, :date, :date, 1, :ip, 'myplace')";

Then use bindParam():

$stmt = $conn->prepare($query);
$stmt->bindParam(':user', $muser);
$stmt->bindParam(':ip', $_SERVER['REMOTE_ADDR']);
$stmt->bindParam(':date', date('Y-m-d H:i:s'));

if($stmt->execute() === TRUE) echo 'success';
else echo 'fail';

Instead of the :date placeholder, if you're using MySQL, you could simply use the NOW() function. Docs: http://php.net/manual/en/pdostatement.bindparam.php

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.