I have a classified script that when someone posts an ad without an image the page where you scroll through all the ads look funky, because some ads of pictures some don't...
So I would like to make it where if someone doesn't post an ad, that there is a generic image that says 'No Image'.
Here's the code:
//Create a new ad in the MySQL table, and upload the given image. $image is a reference to the image in $_FILES
function NewAd($owner_id, $title, $image, $category, $price, $info, $location)
{
$this->sql->query("SELECT * FROM ads WHERE title = '%s'", $title);
//Die if there's another ad with the same name
if($this->sql->num_rows != 0)
{
echo "<script>alert('Sorry. Another ad exists with this title. Please choose another title.');</script>";
return FALSE;
}
//If $image is an array (i.e. not a link to an offsite hosted image)
if(is_array($image))
{
move_uploaded_file($image['tmp_name'], AD_IMAGES.addslashes($title));
$image_url = SERVER_ROOT.AD_IMAGES.addslashes($title);
}
//If $image is the URL to an image hosted elsewhere.
else
$image_url = $image;
//Query to add this information into the db
$this->sql->query("INSERT INTO ads SET owner = '%s', title = '%s', image = '%s', category = '%s', price = '%s', info = '%s', date = '%s', location = '%s'", $owner_id, $title, $image_url, $category, $price, $info, time(), $location);
return TRUE;
}
There is actually two ways to upload a photo... one is the regular way to upload the image through the browse button... the other one is a URL link. I don't need the URL link one if you have to replace that code with another one.
Sorry for the long type, just trying to make sure you all can understand.
Any help is appreciated.
Thanks 🙂