Take the tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have this code:

<?php
include 'config.php';
date_default_timezone_set('America/Los_Angeles');
$d = date('Y-m-d');
$m = date("m");
$day = date("d");
$t = date("His");
$ip = $_SERVER['REMOTE_ADDR'];
$c = file_get_contents('http://api.wipmania.com/'.$ip);

echo "<h2>ALL RESULTS TODAY:</h2><table>";
$_GET['c'] = $c;
$sc = $_GET['sc'];
if($c === "key"){
    if($sc === "t"){
        $result = "SELECT * FROM main WHERE date = '$d' ORDER BY time";
        while($row = mysqli_fetch_array($result))
  {echo "<tr><td>".$row['key'] . "</td><td> " . $row['country']."</td><td>".$row['ip']."</td></tr>";  }
        }

}

echo '</table>';
?>

i have tried without $con: mysqli_fetch_array($result), but it was the same...

But nothings appear... no error no results... Please help... Thanks!

share|improve this question
 
You need to run your query - $result = mysqli_query($con, $sql) or die (mysqli_error($con)), where $sql is the query you want to run, and $con is a valid mysqli database connection. –  andrewsi Aug 30 at 18:47
 
Please, before you write any more SQL interfacing code, you must read up on proper SQL escaping to avoid severe SQL injection bugs. When using mysqli you should be using parameterized queries and bind_param to add user data to your query. Never use string interpolation to accomplish this. –  tadman Aug 30 at 19:03
add comment

3 Answers

up vote 0 down vote accepted

you forgot mysqli_query.

replace this

   $result = "SELECT * FROM main WHERE date = '$d' ORDER BY time";

by

   $result =mysqli_query("SELECT * FROM main WHERE date = '$d' ORDER BY time");
share|improve this answer
add comment

You have not connected to the database or queried your results:

$conn = mysqli_connect($hostname,$username,$password,$dbname) or die(mysqli_error());
//...
$your_query = "SELECT * FROM main WHERE date = '$d' ORDER BY time";
$result = mysqli_query($conn, $your_query);
while ($row = mysqli_fetch_array($result)){
  //...
}
share|improve this answer
add comment

You forgot to perform the query.

$result = mysqli_query($con, "SELECT * FROM main WHERE date = '$d' ORDER BY time");
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.