I'm creating a report page and can't figure out how to convert the array (row) to just get the ip_address. I'm a newbie to php and can't figure out how to accomplish this. Here's the code that I have so far:
<?php
$filename = NULL;
session_start();
// start of script every time.
// setup a path for all of your canned php scripts
$php_scripts = '../php/'; // a folder above the web accessible tree
// load the pdo connection module
require $php_scripts . 'PDO_Connection_Select.php';
if (!$con = PDOConnect("test")):
{
echo "Failed to connect to database" ;
exit;
}
else:
{
$stmt = $con->query("SELECT DISTINCT(IP_ADDRESS) FROM download WHERE FILENAME is not NULL");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)) {
$temp = $row ;
echo var_dump($temp); // shows as "array(1) { ["IP_ADDRESS"]=> string(64) "92.240.60.16" }"
$country = $con->query("SELECT (country) FROM ip_lookup WHERE '$temp' between start_ip and end_ip");
$area = $con->query("SELECT (area) FROM ip_lookup WHERE '$temp' between start_ip and end_ip");
$city = $con->query("SELECT (city) FROM ip_lookup WHERE '$temp' between start_ip and end_ip");
$test = $con->query("UPDATE TABLE download SET country = '$country', area = '$area', city= '$city' WHERE IP_ADDRESS = '$temp' and FILENAME is not NULL") ;
}
All ip_addresses are stored as binary(64) and the errors I'm getting follow:
Notice: Array to string conversion in /home/larry/web/test/public_html/report.php on line 26
Notice: Array to string conversion in /home/larry/web/test/public_html/report.php on line 27
Notice: Array to string conversion in /home/larry/web/test/public_html/report.php on line 28
Recoverable fatal error: Object of class PDOStatement could not be converted to string in /home/larry/web/test/public_html/report.php on line 29
I'd appreciate any guidance you can provide or understandable tutorials you can point me to.
Larry