Jump to content

[SOLVED] if statement for database


kidintraffic

Recommended Posts

I have a form that a user can enter data and upload an image that is stored in a database.  The user doesn't have to upload an image but has to enter data into the rest of the form.  When pulling the information from the database I was wondering how you would say

 

if the database name for the image is empty then display a default image.  and if there is data in the database for the image name then display the image specified.

 

 

I know to display the image that is in the database I use this code

<img src="uploads/<? echo $imgname; ?>" />

 

Link to comment
https://forums.phpfreaks.com/topic/50157-solved-if-statement-for-database/
Share on other sites

$imgname (pulled from that cell in the DB table)

 

if($imgname == NULL) // or whatever you set as default
{ echo "<img src='default.gif'>" /> }
else
{ echo "<img src='uploads/<?=$imgname?>' />" }

   

 

edit:

 

When the form is submitted, you can check to see if they are uploading something or not, and then set the DB cell to whatever you decide :) Then check based on that.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.