1

This line is working perfectly :

$mysqli->query("INSERT INTO `myDatabase`.`myTable`(Date,Time,SID) VALUES (1,2,3)"); 

But this not :

session_start();
$sessionID=session_id();
$mysqli->query("INSERT INTO `myDatabase`.`myTable`(Date,Time,SID) VALUES (1,2,$sessionID)");

I have also tried:

session_start();
$sessionID=session_id();
$mysqli->query("INSERT INTO `myDatabase`.`myTable`(Date,Time,SID) VALUES (1,2,".$sessionID.")");

All table rows defined as TINYTEXT.

Hezi-Gangina
  • 637
  • 6
  • 20
  • 1
    Strings should always be between quotation marks. Like this: `$mysqli->query("INSERT INTO table (column_1 ,column_2) VALUES ('value', '" . $value2 . "')"); ` Also make sure a variable is effective a variable and not simply a string... mentioned as 2nd value in the query – Jeroen Bellemans May 13 '15 at 13:06

2 Answers2

7

You need to pass the variable as a variable to your query ad wrap your values into an "'s, example:

$mysqli->query("INSERT INTO `myDatabase`.`myTable`(Date,Time,SID) VALUES ('1','2','" . $sessionID . "')");
Florian
  • 2,796
  • 1
  • 15
  • 25
1

Thanks to @Jeroen Bellemans and @Florian...

I merge both techniques and it works like a charm ;)

$mysqli->query("INSERT INTO `myDatabase`.`myTable`(Date,Time,SID) VALUES ('1','2','".$sessionID."')");

Thanks guys!

Hezi-Gangina
  • 637
  • 6
  • 20