如何显示存储在数据库中的图像

时间:2016-09-24 10:34:37

标签: php mysql echo

我正在尝试使用mysql和php制作一个小百科全书。我想在搜索名称时显示一些文字,但也显示图像。文本显示得很好,但没有图像。我做错了什么?

<body>
    <p>
    <form name="form" method="post" action="search2.php?go">
    <input type="submit" name="button" value="Display all names from database" style="float: right;"/>
    </form>
    <form method="post" action="search.php?go" id="searchform"style="float:   top;">
<input type="text" name="name">
<input type="submit" name="submit" value="Search" style="float: top;">
</form>
</p>



<?php


if(isset($_POST['submit']))
if(isset($_POST['submit'])){if(isset($_GET['go'])){

if(preg_match("/^[a-zA-Z]+/", $_POST['name'])){$name=$_POST['name'];

$db=mysql_connect  ("host", "username",  "password") or die ('I cannot connect to the database  because: ' . mysql_error()); 

$mydb=mysql_select_db("table");
$sql="SELECT ID, FirstName, LastName, FullName FROM encyclopedia WHERE FirstName LIKE '%" . $name . "%' OR LastName LIKE '%" . $name ."%' OR FullName LIKE '%" . $name ."%' OR NATIONALITY LIKE '%" . $name ."%' OR PROFESSION LIKE '%" . $name ."%' ";

$result=mysql_query($sql);

$numrows=mysql_num_rows($result);
echo "<p>" .$numrows . " results found for " . stripslashes($name) . "</p>"; 

while($row=mysql_fetch_array($result)){
    $FirstName =$row['FirstName'];
    $LastName=$row['LastName'];
    $ID=$row['ID'];     

echo "<ul>\n"; 
echo "<li>" . "<a href=\"search.php?id=$ID\">"  .$FirstName . " " . $LastName . "  </a></li>\n";
echo "</ul>";
}
}
else{
echo "<p>Please enter a search query</p>";
}
}
}
contactid.
if(isset($_GET['id'])){$contactid=$_GET['id'];

 $db=mysql_connect  ("host", "username",  "password") or die ('I cannot connect to the database  because: ' . mysql_error()); 

$mydb=mysql_select_db("table");

$sql="SELECT * FROM encyclopedia WHERE ID=" . $contactid;

$result=mysql_query($sql); 

while($row=mysql_fetch_array($result)){
    $INFO=$row['INFO'];

echo "<ul>\n"; 
echo "<li>" . $INFO. "</li>\n";
echo '<img src="data:image/jpeg;base64,'.base64_encode($image->load()) .'" />';
echo "</ul>";
}
}
?>

<?php

if(isset($_POST['button'])){
$db=mysql_connect  ("mysql19.cliche.dk", "boersting.name",  "xC1ZNSiP") or die ('I cannot connect to the database  because: ' . mysql_error()); 
$mydb=mysql_select_db("boersting_name");
$sql="SELECT ID, FullName FROM encyclopedia WHERE FullName LIKE '%" . $FullName. "%' ORDER BY FULLNAME ";
$result=mysql_query($sql); 
while($row=mysql_fetch_array($result)){
$FullName=$row['FullName'];
$ID=$row['ID'];

echo "<ul>\n"; 
echo "<li>" .$FullName. "</li>\n";
}}
?>



</body>
</html>

0 个答案:

没有答案