我正在尝试制作一个PHP代码,如果我在数据库中放入一个URL,代码将会在该URL上找到它并查看它获得的HTTP代码但目前所做的只是给我HTTP - 代码0而不是怀特。
$username = "root";
$password = "luca170385";
$hostname = "localhost";
$dbhandle = mysqli_connect($hostname, $username, $password)
or file_put_contents($filename, date("Y-m-d H:i:s")."Unable to connect to database", FILE_APPEND);
echo "Connect to MySQL<br>";
$selected = mysqli_select_db($dbhandle , "accounts")
or file_put_contents($filename, date("Y-m-d H:i:s")."Could not select database<br>", FILE_APPEND);
echo "Selected Database<br>";
$sql = "SELECT `address` FROM `url` WHERE `code` IS NULL";
if ($result = mysqli_query($dbhandle, $sql)){
while ($row = mysqli_fetch_assoc( $result));{
printf ($row['address']);
$output = "{$row['address']}";
echo "{$row['address']}";
$handle = curl_init($sql);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$update = "UPDATE url SET `code`= $httpCode WHERE `address` = $sql";
echo "$update.<br>";
echo "$handle.<br>";
echo "$httpCode.<br>";
mysqli_query($dbhandle, $update);
echo "{$row['address']}";
curl_close($handle);
}
}else {
echo 'Not working';
}
答案 0 :(得分:2)
;
会终止,因此它是空的。
while ($row = mysqli_fetch_assoc( $result));
因此,您只需删除;
。
答案 1 :(得分:1)
检查评论: -
<?php
error_reporting(E_ALL);// check all type of error
ini_set('display_errors',1);// display those errors
$username = "root";
$password = "luca170385";
$hostname = "localhost";
$dbhandle = mysqli_connect($hostname, $username, $password, "accounts");
/*or file_put_contents($filename, date("Y-m-d H:i:s")."Unable to connect to database", FILE_APPEND);
echo "Connect to MySQL<br>";*/// from where this $filename come from?
/*$selected = mysqli_select_db($dbhandle ,)
or file_put_contents($filename, date("Y-m-d H:i:s")."Could not select database<br>", FILE_APPEND);
echo "Selected Database<br>";*/ //not needed
$sql = "SELECT `address` FROM `url` WHERE `code` IS NULL";
if ($result = mysqli_query($dbhandle, $sql)){
while ($row = mysqli_fetch_assoc( $result)){ // remove ;
printf ($row['address']);
$output = $row['address']; // remove {} and ""
echo $row['address']; // remove {} and ""
$handle = curl_init($sql);
curl_setopt($handle, CURLOPT_RETURNTRANSFER, TRUE);
$response = curl_exec($handle);
$httpCode = curl_getinfo($handle, CURLINFO_HTTP_CODE);
$update = "UPDATE url SET `code`= $httpCode WHERE `address` = $output"; // not $sql
echo "$update.<br>";
echo "$handle.<br>";
echo "$httpCode.<br>";
mysqli_query($dbhandle, $update);
echo $row['address'];// remove {} and ""
curl_close($handle);
}
}else {
echo 'Not working';
}