Do you save the directory in the image in varchar? if so, try modifying your database to save the image using BLOB as described here
Then you can use the if statement.
<img src="<? php if($row["file"]){echo $row["file"];} else { echo '/directory/to/image.jpg'}?>" height="100px" width="150px">
I would also recommend using include, it may not be 100% relevant for your current project, but it can help if you need to use more than one database connection.
- create dbconnect.php file // name it whatever you want
- paste the code into the dbconnect.php file:
<? php $con=mysql_connect("localhost","root","") or die ("no connection"); mysql_select_db("project")or die("no database exit");?>
- in any file that you use to use the
include_once 'dbconnect.php' database include_once 'dbconnect.php'
source share