Jump to content

[SOLVED] Form Inserting to mysql then echoing a image from the database to a webpage


Recommended Posts

I’m echoing results to a page I have a form that inserts data to mysql

 

$query = "INSERT into `".$db_table."` (venue,address,date_1,time_1,date_2,time_2,date_3,time_3,date_4,time_4,host,host_email,venue_website,venue_phone,logo_image) VALUES ('" . $_POST['venue'] . "','" . $_POST['address'] . "','" . $_POST['date_1'] . "','" . $_POST['time_1'] . "','" . $_POST['date_2'] . "','" . $_POST['time_2'] . "','" . $_POST['date_3'] . "','" . $_POST['time_3'] . "','" . $_POST['date_4'] . "','" . $_POST['time_4'] . "','" . $_POST['host'] . "','" . $_POST['host_email'] . "','" . $_POST['venue_website'] . "','" . $_POST['venue_phone'] . "','" . $_POST['logo_image'] . "')";
mysql_query($query);
mysql_close($link);
//This sends an email with results from form summated. Which gives a link to image when clicked it shows the image.
mail("admin@email.com","Venue Form submissions","Venue data:

Venue: " . $_POST['venue'] . " 
Address: " . $_POST['address'] . " 
Date1: " . $_POST['date_1'] . " Time1: " . $_POST['time_1'] . " 
Date2: " . $_POST['date_2'] . " Time2: " . $_POST['time_2'] . " 
Date3: " . $_POST['date_3'] . " Time3: " . $_POST['time_3'] . " 
Date4: " . $_POST['date_4'] . " Time4: " . $_POST['time_4'] . " 
Host: " . $_POST['host'] . " Host Email: " . $_POST['host_email'] . " 
Venues Website: " . $_POST['venue_website'] . " 
Venues Phone: " . $_POST['venue_phone'] . " 
Venues Logo: ".$where_form_is."files/".$logo_image_filename." (original file name: " . $_FILES['logo_image']['name'] . ")

");

But if I look at the database table field logo_imagae it is empty. This echo’s the results of submitted page.

$query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100';

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {

    if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n"; 
    if (!empty($row['address'])) echo $row['address']."<br />\n"; 
    if (!empty($row['date_1'])) echo $row['date_1']." ";
    if (!empty($row['time_1'])) echo $row['time_1']."<br />\n"; 
    if (!empty($row['date_2'])) echo $row['date_2']."  ";
    if (!empty($row['time_2'])) echo $row['time_2']."<br />\n"; 
    if (!empty($row['date_3'])) echo $row['date_3']."  "; 
    if (!empty($row['time_3'])) echo $row['time_3']."<br />\n"; 
    if (!empty($row['date_4'])) echo $row['date_4']."  "; 
    if (!empty($row['time_4'])) echo $row['time_4']."<br />\n"; 
    if (!empty($row['host'])) echo "Host: ".$row['host']."  "; 
    if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n"; 
    if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n"; 
    if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; 
    if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n";
//tried this to echo image but displays X image
    echo "<img src='/venue/files/' ".$row['logo_image']." '>"; 
echo "<hr>";
}

 

No image from logo_image is displayed. the image is stored in a directory I tried the part at // and it gives me a X image but the actual image isn’t displayed I believe because the field is empty and doesn’t know what to get to display. So how do I insert the file name into the logo_image field and what do I do to echo the image on the page.

change

echo "<img src='/venue/files/' ".$row['logo_image']." '>"; 

to

echo "<img src='/venue/files/".$row['logo_image']."'>"; 

that will display an image if their is one, but if theirs no image your need a default image ie

$noImage = "MyNoImageImage.jpg";
$img = (empty($row['logo_image']))?$noImage:$row['logo_image'];
echo "<img src='/venue/files/$img'>"; 

http://www.mysite.com/starsite/venue/files/

http://www.mysite.com/starsite/venue/files/parachute_01.jpg

change noimage to one in folder to see if worked I will make a noimage after it works and yes there are images in directory

   

echo "<img src='admin/venue/files/".$row['logo_image']."'>"; 


$noImage = "parachute_01.jpg";
$img = (empty($row['logo_image']))?$noImage:$row['logo_image'];
echo "<img src='admin/venue/files/$img'>";  

Still didnt work here what the page displays

EyeRock Night Club

123 Some Address

05/23/2009 9:ooPm to 2:00Am

05/30/2009 8:ooPm to 1:00Am

06/06/2009 7:ooPm to 12:00Am

06/20/2009 9:ooPm to 2:00Am

Host: Wild Bill Host Email: WildBill@dong.ding

www.EyeRock.net

316-838-2222

HERES WHERE THE X image is showing up.

 

$query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100';

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {

    if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n"; 
    if (!empty($row['address'])) echo $row['address']."<br />\n"; 
    if (!empty($row['date_1'])) echo $row['date_1']." ";
    if (!empty($row['time_1'])) echo $row['time_1']."<br />\n"; 
    if (!empty($row['date_2'])) echo $row['date_2']."  ";
    if (!empty($row['time_2'])) echo $row['time_2']."<br />\n"; 
    if (!empty($row['date_3'])) echo $row['date_3']."  "; 
    if (!empty($row['time_3'])) echo $row['time_3']."<br />\n"; 
    if (!empty($row['date_4'])) echo $row['date_4']."  "; 
    if (!empty($row['time_4'])) echo $row['time_4']."<br />\n"; 
    if (!empty($row['host'])) echo "Host: ".$row['host']."  "; 
    if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n"; 
    if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n"; 
    if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; 
    if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n";

$noImage = "parachute_01.jpg";
$img = (empty($row['logo_image']))?$noImage:$row['logo_image'];
echo "<img src='admin/venue/files/$img'>"; 

 

 

to my above post I tried this as well

    if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n"; 
echo "<img src='/venue/files/".$row['logo_image']."'>";

$noImage = "MyNoImageImage.jpg";
$img = (empty($row['logo_image']))?$noImage:$row['logo_image'];
echo "<img src='admin/venue/files/$img'>";  

 

<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Venues</title>

<script src="css_js/nav.js"></script>
<script type="text/javascript" src="css_js/ajaxcontent.js">
</script>

<body class="body">
    <div id="header" align="center">
    <script>document.write(header());</script>
    </div>

</head>

<body class="body">

<div align="center">

<table border="0" width="500px" cellspacing="1">
<tr>
	<td>
<b>Papas Bar & Grill</b><br />
123 elm<br />
<img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg'><hr><b>EyeRock Night Club</b><br />
123 Some Address<br />
05/23/2009 9:ooPm to 2:00Am<br />
05/30/2009  8:ooPm to 1:00Am<br />
06/06/2009  7:ooPm to 12:00Am<br />
06/20/2009  9:ooPm to 2:00Am<br />
Host: Wild Bill  Host Email: WildBill@dong.ding<br />
www.EyeRock.net<br />
316-838-2222<br />
<img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg'><hr> </td>
</tr>
</table>
</div>

<div style="position: absolute; width: 160px; left: 20px; top: 110px" id="topleft"><script>document.write(menu());</script>
 </div>

<div style="position: absolute; width: 230px; right: 5px; top: 110px" id="topright"> 
</div>

<script type="text/javascript">
ajaxpage('admin/venues/venuespg.php','topright') //load "test.htm" into "lefttop" DIV
</script>

<p align="center">
<IMG src="images/musicstaff.gif" width="480" height="25"><BR>

<FONT face="Arial, Helvetica, sans-serif" size=1>
</p>
<div id="menu2" align="center">
<script>document.write(menu2());</script>
</div>
</FONT>


</body>

</html>

<img src='/venue/files/'><img src='admin/venue/files/MyNoImageImage.jpg'

as i said you need to remove echo "<img src='/venue/files/".$row['logo_image']."'>"; and does this MyNoImageImage.jpgimage exist in this admin/venue/files/ path ?

oK noimage.jpg shows now " I had it misspelled", but I used the form to upload image so it should show, I would think but again I dont understand how if in the DB the logo_image field is blank. So now what to do?

 

$query = "INSERT into `".$db_table."` (venue,address,date_1,time_1,date_2,time_2,date_3,time_3,date_4,time_4,host,host_email,venue_website,venue_phone,logo_image) VALUES ('" . $_POST['venue'] . "','" . $_POST['address'] . "','" . $_POST['date_1'] . "','" . $_POST['time_1'] . "','" . $_POST['date_2'] . "','" . $_POST['time_2'] . "','" . $_POST['date_3'] . "','" . $_POST['time_3'] . "','" . $_POST['date_4'] . "','" . $_POST['time_4'] . "','" . $_POST['host'] . "','" . $_POST['host_email'] . "','" . $_POST['venue_website'] . "','" . $_POST['venue_phone'] . "','" . $_POST['logo_image'] . "')";
mysql_query($query);
mysql_close($link);

 

in the field is blank AKA empty, then that where this line is usful

$img = (empty($row['logo_image']))?$noImage:$row['logo_image'];

 

its a shorthand version of this

if(empty($row['logo_image']))
{
$img = $noImage;
}else{
$img = $row['logo_image'];
}

so if the $row['logo_image'] is empty  then $img = $noImage; otherwise $img = $row['logo_image'];

yeah use the long one..

 

okay heres some new code,

 

if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n";
if(empty($row['logo_image']) && true) //debug
{
echo "<img src='admin/venue/files/MyNoImageImage.jpg'>";  // no image
}else{
echo "<img src='admin/venue/files/{$row['logo_image']}'>";  found image
}

 

first update

echo "<img src='admin/venue/files/MyNoImageImage.jpg'>";  // no image

so it displays an image (during the first test this will always display)

 

once that displays

remove "&& true"

if(empty($row['logo_image']) && true) //debug

and make sure the path on the line below is correct

 

then test again

I tried it with the && true and without it got the same results both ways the noimage showed, but not the one uploaded thru form. Heres what the mysql DB looks like field names and data

 

venue | address | date_1 | time_1 | date_2 | time_2 | date_3 | time_3 | date_4 | time_4 | host | host_email | venue_website | venue_phone | logo_image

EyeRock Night Club 123 Some Address 05/23/2009 9:ooPm to 2:00Am 05/30/2009 8:ooPm to 1:00Am 06/06/2009 7:ooPm to 12:00Am 06/20/2009 9:ooPm to 2:00Am Wild Bill WildBill@dong.ding www.EyeRock.net 316-838-2222

The && TRUE makes sure it used the MyNoImageImage.jpg,

now thats showing you remove the && TRUE

as you said you aree getting the same results thats to be expected as the data you posted has no image!

I tried this

	if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n";

while ( $row = mysql_fetch_array ($logo_image) )
{
$logo_image = $row["logo_image"]; //picname is the name of the field in the images table
}
if(empty($row['logo_image']) && true) //debug
{
echo "<img src='admin/venues/files/noimage.gif'>";  // no image
}else{
echo "<img src='admin/venues/files/{$row['logo_image']}'>";  // found image

}

echo "<hr>";
}

Got this error but it shows the noimage image

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /public_html/venues.php on line 61

line 61 is while ( $row = mysql_fetch_array ($logo_image) )

 

Okay well that code will never work..

 

if you keep changing random parts this will never get resolved!

 

your code should look like this

 

$query= 'SELECT venue, address, date_1, time_1, date_2, time_2, date_3, time_3, date_4, time_4, host, host_email, venue_website, venue_phone, logo_image FROM Venues ORDER BY date_1 ASC LIMIT 0, 100';

$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)) {

    if (!empty($row['venue'])) echo "<b>".$row['venue']."</b><br />\n";
    if (!empty($row['address'])) echo $row['address']."<br />\n";
    if (!empty($row['date_1'])) echo $row['date_1']." ";
    if (!empty($row['time_1'])) echo $row['time_1']."<br />\n";
    if (!empty($row['date_2'])) echo $row['date_2']."  ";
    if (!empty($row['time_2'])) echo $row['time_2']."<br />\n";
    if (!empty($row['date_3'])) echo $row['date_3']."  ";
    if (!empty($row['time_3'])) echo $row['time_3']."<br />\n";
    if (!empty($row['date_4'])) echo $row['date_4']."  ";
    if (!empty($row['time_4'])) echo $row['time_4']."<br />\n";
    if (!empty($row['host'])) echo "Host: ".$row['host']."  ";
    if (!empty($row['host_email'])) echo "Host Email: ".$row['host_email']."<br />\n";
    if (!empty($row['venue_website'])) echo $row['venue_website']."<br />\n";
    if (!empty($row['venue_phone'])) echo $row['venue_phone']."<br />\n";
    if (!empty($row['logo_image'])) echo $row['logo_image']."<br />\n";
//tried this to echo image but displays X image

    if(empty($row['logo_image'])) //debug
    {
        echo "<img src='admin/venues/files/noimage.gif'>";  // no image
    }else{
        echo "<img src='admin/venues/files/{$row['logo_image']}'>";  // found image
    }
    echo "<img src='/venue/files/' ".$row['logo_image']." '>";
echo "<hr>";
}

Sighs!

 

okay well the fix is

    if(empty($row['logo_image']))
    {
        echo "<img src='admin/venues/files/noimage.gif'>";  // no image
    }else{
        echo "<img src='admin/venues/files/{$row['logo_image']}'>";  // found image
    }

 

thats how you display the image a default image if the value in the database is empty

 

the red cross means it can't find the image, (double check the path and the image name)

 

Im sorry this is taking so long Im frustrated.. I changed to what you have in the last post deleted all past form data and images in the files folder and made 1 new entry with a small image.

I get the noimage pic to show but not the one I uploaded. checked the files dir and it is there.

 

Its like it doesnt see anything in the logo_image field to go get. the field is blank if I look at the sql table, so it leads me to believe I got something wrong in the process of the form. ???

thats correct, if the database's field is empty then the image can't be found (it doesn't know its name), thus a default image is showed in its place,

 

check the upload code, (or post it)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.