拥有从经典mysql中获取图像的代码,这种方式非常有效:
<?php
mysql_connect("localhost", "root", "");
mysql_select_db("front");
$submit=$_GET['str'] ;
$sql = mysql_query("SELECT * FROM searcengine WHERE pagecontent LIKE '%$_GET[$submit]%' ");
while($row=mysql_fetch_array($sql)) {
echo "<img src=image_2.php?pagecontent=".$row['pagecontent']." />";
}
?>
和image_2.php:
<?php
ini_set('display_errors',1);
error_reporting(E_ALL);
$conn = mysql_connect("localhost","root","");
if(!$conn)
{
echo mysql_error();
}
$db = mysql_select_db("front",$conn);
if(!$db)
{
echo mysql_error();
}
$pagecontent = $_GET['pagecontent'];
$q = "SELECT pageurl FROM searchengine where pagecontent='$pagecontent'";
$sql = mysql_query("$q",$conn);
if($sql)
{
$row = mysql_fetch_array($sql);
header("Content-type: image/jpeg");
echo $row['pageurl'];
}
else
{
echo mysql_error();
}
?>
现在,我更新了最新的mysqli代码如下:
<?php
$con=mysqli_connect("localhost","root","","front");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$submit=$_GET['str'] ;
$sql="SELECT * FROM 'searchengine' WHERE 'pagecontent' = '%$submit%' ";
if ($result=mysqli_query($con,$sql))
{
// Fetch one and one row
while ($row=mysqli_fetch_assoc($result)) {
echo "<img src=image_2.php?pagecontent=".$row['pagecontent']." />";
}
}
mysqli_close($con);
?>
和image2.php =
<?php
$con=mysqli_connect("localhost","root","","front");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$pagecontent = $_GET['pagecontent'];
if (!empty($pagecontent)) {
$sql= "SELECT 'pageurl' FROM 'searchengine' where 'pagecontent'='$pagecontent'";
if ($result=mysqli_query($con,$sql))
{
while ($row = mysqli_fetch_assoc($result));
header("Content-type: image/jpeg");
echo $row['pageurl'];
}
?>
但在这种情况下,即。图片没有显示。帮助我有什么不对吗?
答案 0 :(得分:1)
为什么要在新文件中打开img,试试这个:
<?php define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'front');
$conn = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
if (!$conn){ die('Failed to connect to server: ' . mysql_error());
exit;}
$submit=$_GET['str'];
$stmt = $conn->prepare("SELECT pageurl FROM searchengine WHERE pagecontent='%$submit%'");
$stmt->bind_param("i", $submit;
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($pageurl );
$stmt->fetch();
header("Content-Type: image/jpeg");
echo $pageurl ;?>
请记住:我将*
替换为您在帖子中搜索的pageurl
内容。
甚至,不能发布你的sql和表单。