user775171
user775171

Reputation:

PHP/mySQLi not querying

<?php

$ip = $_SERVER['REMOTE_ADDR'];
$date = date("d/m/y : H:i:s", time());

$dbc = mysqli_connect('localhost', 'root', 'derp', 'derpdb')
  or die("Database connection fried.");

$query = "INSERT INTO ipstore (tstamp, ip), " .
  "VALUES ('$date', '$ip')";

mysqli_query($dbc, $query);

mysqli_close($dbc);

?>

Can anyone tell me what's wrong with this code? It's meant to store the users IP/date they requested the page in the database. I've tried replacing localhost with 127.0.0.1, no luck. It doesn't bring a message, so it must be connected, however when it comes to querying it just doesn't do it. And it doesn't give a warning. I've checked the DB, nothings there.

Also don't worry, nothing sensitive is there ;)

Thanks

Upvotes: 1

Views: 199

Answers (2)

w0bni
w0bni

Reputation: 72

$query = "INSERT INTO ipstore (tstamp, ip), " . "VALUES ('$date', '$ip')";

You are not supposed to use a comma after specifying columns - try

$query = "INSERT INTO ipstore (tstamp, ip) VALUES ('$date', '$ip')";

Upvotes: 1

Jonathan
Jonathan

Reputation: 51

try it this way

    $query = mysql_query("INSERT INTO ipstore (tstamp,ip) VALUES ('$date', '$ip')") or die(mysql_error()); if($query) {echo 'Success'; esle { echo 'Failed'; }

And you will get success for sure

Upvotes: 0

Related Questions