1

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!

2
  • 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. Commented Aug 30, 2013 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. Commented Aug 30, 2013 at 19:03

3 Answers 3

1

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)){
  //...
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

You forgot to perform the query.

$result = mysqli_query($con, "SELECT * FROM main WHERE date = '$d' ORDER BY time");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.