开发者

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 f开发者_如何转开发ried.");

$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


$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')";


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜