• Jetzt anmelden. Es dauert nur 2 Minuten und ist kostenlos!

Bild aus MYSQL in PHP ausgeben

high2fly

Neues Mitglied
Hallo,

Ich habe ein Problem mit einer meiner php dateien, ich schaffe es einfach nicht eine Fehlermeldung wegzubekommen die immer hochpoppt wenn ich den header bearbeiten will.

ich habe auch schon in den anderen threads über dieses Thema rumgesucht und getestet, aber leider ohne erfolg...

Bitte um Hilfe

index.php
HTML:
<html>
<body>
<div class="dark">
<style type="text/css">
body {
background: #fafafa url(dark_grey.jpg);
color: #444;
font: 100%/30px 'Helvetica Neue', helvetica, arial, sans-serif;
text-shadow: 0 1px 0 #fff;
}
strong {
font-weight: bold;
}
em {
font-style: italic;
}
table {
background: #f5f5f5;
border-collapse: separate;
box-shadow: inset 0 1px 0 #fff;
font-size: 12px;
line-height: 24px;
margin: 30px auto;
text-align: left;
width: 800px;
}
th {
background: url(images/noise-diagonal.png), linear-gradient(#777, #444);
border-left: 1px solid #555;
border-right: 1px solid #777;
border-top: 1px solid #555;
border-bottom: 1px solid #333;
box-shadow: inset 0 1px 0 #999;
color: #fff;
font-weight: bold;
padding: 10px 15px;
position: relative;
text-shadow: 0 1px 0 #000;
}
th:after {
background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,.08));
content: '';
display: block;
height: 25%;
left: 0;
margin: 1px 0 0 0;
position: absolute;
top: 25%;
width: 100%;
}
th:first-child {
border-left: 1px solid #777;
box-shadow: inset 1px 1px 0 #999;
}
th:last-child {
box-shadow: inset -1px 1px 0 #999;
}
td {
border-right: 1px solid #fff;
border-left: 1px solid #e8e8e8;
border-top: 1px solid #fff;
border-bottom: 1px solid #e8e8e8;
padding: 10px 15px;
position: relative;
transition: all 300ms;
}
td:first-child {
box-shadow: inset 1px 0 0 #fff;
}
td:last-child {
border-right: 1px solid #e8e8e8;
box-shadow: inset -1px 0 0 #fff;
}
tr {
background: url(images/noise-diagonal.png);
}
tr:nth-child(odd) td {
background: #f1f1f1 url(images/noise-diagonal.png);
}
tr:last-of-type td {
box-shadow: inset 0 -1px 0 #fff;
}
tr:last-of-type td:first-child {
box-shadow: inset 1px -1px 0 #fff;
}
tr:last-of-type td:last-child {
box-shadow: inset -1px -1px 0 #fff;
}
tbody:hover td {
color: transparent;
text-shadow: 0 0 3px #aaa;
}
tbody:hover tr:hover td {
color: #444;
text-shadow: 0 1px 0 #fff;
}
</style><br>
<h1 align="center" style="color:white">Übersicht:</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Verkäufer</th>
<th>Preis</th>
<th>Kategorie</th>
<th>Einstellungsdatum</th>
<th>Ort</th>
<th>Plz</th>
<th>E-Mail</th>
</tr>
<?php include "formular.php"; ?>
</div>
</body>
</html>

formular.php
PHP:
<?php
$id = 5;
// Verbindung herstellen
$host = "****";
$user = "****";
$pass = "****";
$db = "****";
mysql_connect($host, $user, $pass);
mysql_select_db($db);
unset($host,$user,$pass,$db);
$query="select * from verkaufen_tbl order by ID ASC ";
$result = mysql_query($query);
while ($results = mysql_fetch_array($result))
{
echo"<p>
<tbody>
<tr>
<td><strong>".$results['id']."</strong></td>
<td>".$results['title']."</td>
<td>".$results['member']."</td>
<td>".$results['preis']." Euro</td>
<td>".$results['article']."</td>
<td>".$results['datum']."</td>
<td>".$results['ort']."</td>
<td>".$results['plz']."</td>
<td><b>E-Mail:</b><a href= mailto:".$results['mail'].">".$results['mail']."</a></td>
</tr></p></font>";
include "bild.php";
}
?>

bild.php
PHP:
<?header('Content-Type: image/jpg')?>
<?
$host = "****";
$user = "****";
$pass = "****";
$db = "****";
mysql_connect($host, $user, $pass);
mysql_select_db($db);
unset($host,$user,$pass,$db);
$sql = 'SELECT image FROM verkaufen_tbl WHERE id = 2';
$result = mysql_query($sql);
$bild = mysql_fetch_row($result);
echo $bild[0];
?>

Die Fehlermeldung lautet
Warning: Cannot modify header information - headers already sent by (output started at /****/****/****/****/index.php:110) in /****/****/****/****/bild.php on line 1


(Und ja ich weiß das man den code an etlichen stellen verbessern kann und 2 Datenbankverbindungen sowieso schwachsinn sind aber es geht mir gerade nur im diesen header Fehler)
 
Nicht
PHP:
include "bild.php";
sondern
HTML:
<img src="bild.php" alt="">
 
Wie folgt abgeändert:

index.php
HTML:
<html>
<body>
<div class="dark">
<style type="text/css">
body {
background: #fafafa url(dark_grey.jpg);
color: #444;
font: 100%/30px 'Helvetica Neue', helvetica, arial, sans-serif;
text-shadow: 0 1px 0 #fff;
}
strong {
font-weight: bold;
}
em {
font-style: italic;
}
table {
background: #f5f5f5;
border-collapse: separate;
box-shadow: inset 0 1px 0 #fff;
font-size: 12px;
line-height: 24px;
margin: 30px auto;
text-align: left;
width: 800px;
}
th {
background: url(images/noise-diagonal.png), linear-gradient(#777, #444);
border-left: 1px solid #555;
border-right: 1px solid #777;
border-top: 1px solid #555;
border-bottom: 1px solid #333;
box-shadow: inset 0 1px 0 #999;
color: #fff;
font-weight: bold;
padding: 10px 15px;
position: relative;
text-shadow: 0 1px 0 #000;
}
th:after {
background: linear-gradient(rgba(255,255,255,0), rgba(255,255,255,.08));
content: '';
display: block;
height: 25%;
left: 0;
margin: 1px 0 0 0;
position: absolute;
top: 25%;
width: 100%;
}
th:first-child {
border-left: 1px solid #777;
box-shadow: inset 1px 1px 0 #999;
}
th:last-child {
box-shadow: inset -1px 1px 0 #999;
}
td {
border-right: 1px solid #fff;
border-left: 1px solid #e8e8e8;
border-top: 1px solid #fff;
border-bottom: 1px solid #e8e8e8;
padding: 10px 15px;
position: relative;
transition: all 300ms;
}
td:first-child {
box-shadow: inset 1px 0 0 #fff;
}
td:last-child {
border-right: 1px solid #e8e8e8;
box-shadow: inset -1px 0 0 #fff;
}
tr {
background: url(images/noise-diagonal.png);
}
tr:nth-child(odd) td {
background: #f1f1f1 url(images/noise-diagonal.png);
}
tr:last-of-type td {
box-shadow: inset 0 -1px 0 #fff;
}
tr:last-of-type td:first-child {
box-shadow: inset 1px -1px 0 #fff;
}
tr:last-of-type td:last-child {
box-shadow: inset -1px -1px 0 #fff;
}
tbody:hover td {
color: transparent;
text-shadow: 0 0 3px #aaa;
}
tbody:hover tr:hover td {
color: #444;
text-shadow: 0 1px 0 #fff;
}
</style><br>
<h1 align="center" style="color:white">Übersicht:</h1>
<table>
<tr>
<th>ID</th>
<th>Name</th>
<th>Verkäufer</th>
<th>Preis</th>
<th>Kategorie</th>
<th>Einstellungsdatum</th>
<th>Ort</th>
<th>Plz</th>
<th>E-Mail</th>
<th>Vorschaubild</th>
</tr>
<?php include "formular.php"; ?>
</div>
</body>
</html>

formular.php
PHP:
<?php
require_once '../dbconnect.php';
$query="select * from verkaufen_tbl order by ID ASC ";
$result = mysql_query($query);
while ($results = mysql_fetch_array($result))
{
echo"<p>
<tbody>
<tr>
<td><strong>".$results['id']."</strong></td>
<td>".$results['title']."</td>
<td>".$results['member']."</td>
<td>".$results['preis']." Euro</td>
<td>".$results['article']."</td>
<td>".$results['datum']."</td>
<td>".$results['ort']."</td>
<td>".$results['plz']."</td>
<td><b>E-Mail:</b><a href= mailto:".$results['mail'].">".$results['mail']."</a></td>
<td><img src='bild.php'></td>";
}
?>

bild.php
PHP:
<?php
require_once '../dbconnect.php';
    // Bild ausgeben
    $id = addslashed($_GET['id']);
    $result = mysql_query("SELECT image, mimetype FROM verkaufen_tbl WHERE id='$id'");
    $row = mysql_fetch_object($result);
    header("Content-type: $row->mimetype");
    echo $row->image;
?>


Jetziges Problem:
Die Bilder werden nicht angezeigt, in MYSQL werden sie Problemlos aufgerufen
 
Und was passiert, wenn du bild.php mal direkt im Browser aufrufst?
 
einen Fehler behoben: addslashed --> addslashes

wenn ich bild.php direkt im browser aufrufe bekomm ich nur eine leere seite angezeigt obwohl er eigentlich alle bilder von reiter Image und die dazugehörigen daten vom reiter mimetype ausgeben sollte...

und ja, wenn ich die bin datei im blob feld öffne, dann wird mir das bild angezeigt...

aber danke für den Tipp, sonst hätte ich das addslashed wahrscheinlich einfach übersehn :D
 
wenn ich bild.php direkt im browser aufrufe bekomm ich nur eine leere seite angezeigt
Damit wäre der Fehler ja schon mal eingekreist, denn eigentlich müsstest du ja ein Bild sehen.

Ahhhhh, warte mal, in bild.php benutzt du ja einen Parameter. Versuche es dann mal mit

PHP:
<img src="bild.php?id=<?php echo $_GET['id']; ?>" alt="">
Und beim direkten Aufruf von bild.php musst du im Browser natürlich auch noch einen Parameter an der Url dranhängen
 
Einfach unfassbar... so ein kleiner Fehler und treibt mich fast in den wahnsinn....

naja auf jeden fall hast es geklappt, vielen dank :D
 
eine kleine Sache noch :) wenn ich den text genau so übernehme bekomme ich einen Fehler, bei den ganzen Semikolons und hochkommas blick ich grad nicht mehr durch, wieso da die Formatierung nicht stimmt :(

PHP:
<?php
require_once '../dbconnect.php';
$query="select * from verkaufen_tbl order by ID ASC ";
$result = mysql_query($query);
while ($results = mysql_fetch_array($result))
{
echo"<p>
<tbody>
<tr>
<td><strong>".$results['id']."</strong></td>
<td>".$results['title']."</td>
<td>".$results['member']."</td>
<td>".$results['preis']." Euro</td>
<td>".$results['article']."</td>
<td>".$results['datum']."</td>
<td>".$results['ort']."</td>
<td>".$results['plz']."</td>
<td><b>E-Mail:</b><a href= mailto:".$results['mail'].">".$results['mail']."</a></td>
<td><img src="bild.php?id=<?php echo $_GET['id']; ?>" alt=""></td>";
}
?>

Fehler:

Parse error: syntax error, unexpected 'bild' (T_STRING), expecting ',' or ';' in /****/****/****/****/formular.php on line 19
 
eine kleine Sache noch :) wenn ich den text genau so übernehme bekomme ich einen Fehler, bei den ganzen Semikolons und hochkommas blick ich grad nicht mehr durch, wieso da die Formatierung nicht stimmt :(

PHP:
<?php
require_once '../dbconnect.php';
$query="select * from verkaufen_tbl order by ID ASC ";
$result = mysql_query($query);
while ($results = mysql_fetch_array($result))
{
echo"<p>
<tbody>
<tr>
<td><strong>".$results['id']."</strong></td>
<td>".$results['title']."</td>
<td>".$results['member']."</td>
<td>".$results['preis']." Euro</td>
<td>".$results['article']."</td>
<td>".$results['datum']."</td>
<td>".$results['ort']."</td>
<td>".$results['plz']."</td>
<td><b>E-Mail:</b><a href= mailto:".$results['mail'].">".$results['mail']."</a></td>
<td><img src="bild.php?id=<?php echo $_GET['id']; ?>" alt=""></td>";
}
?>

Fehler:

Parse error: syntax error, unexpected 'bild' (T_STRING), expecting ',' or ';' in /****/****/****/****/formular.php on line 19

In Zeile 19 (vor bild.php) stimmt es nicht mehr ;)
Eigentlich schon vorher, aber das führt noch nicht zum Parse error, da dies nur ein HTML-Fehler ist.
 
Zurück
Oben