0

I tried to create a script which will save all the IP address that came to my website (for adwords checking purposes). However when I try, the code doesnt save to database at all. Here is the code:

<?php
session_start();

// Create connection
$mysqli = new mysqli("localhost", "hashmicr_admineq", "monkeycool100", "hashmicr_sessionchecker");

date_default_timezone_set('Asia/Singapore');

$date = date("Y-m-d H:i:s");
$query = "INSERT INTO sessioncheck(ipaddress,date) VALUES (".$_SERVER['SERVER_ADDR'].", ".$date.")";
$mysqli->query($query);


/* close connection */
$mysqli->close();
?>

This is placed on the top of the PHP page.

Did I miss on any steps?

RickyHalim
  • 295
  • 6
  • 22

1 Answers1

1

Need to add single quotes as both the field values contain non-numeric (other than 0-9) characters.

You can insert only numeric without single quotes.

Corrected SQL:

$query = "INSERT INTO sessioncheck(ipaddress,date)
VALUES ('".$_SERVER['SERVER_ADDR']."', '".$date."')";
Pupil
  • 23,834
  • 6
  • 44
  • 66