On my image process page I want to first check to see that the picture title ($item_title) isn't in use, if not the script moves to the next conditional.
Now we check to make sure that the image name ($image) isn't already in the database. (The file name is $image and the table row is image_name.) If the image name isn't in the database the script continues.
I have tested for the picture title and the script will fail and return an error message if the picture title is in use. But I it doesn't work for the image name.
I use an image that I know is already in the database, so the script should terminate and display an error message, it's terminating but I'm not getting an error message. The information isn't being entered, as I have both $item_title and $image_name set as unique keys in the database table.
Here's the code:
Any ideas as to what I'm doing wrong?
Thanks
Now we check to make sure that the image name ($image) isn't already in the database. (The file name is $image and the table row is image_name.) If the image name isn't in the database the script continues.
I have tested for the picture title and the script will fail and return an error message if the picture title is in use. But I it doesn't work for the image name.
I use an image that I know is already in the database, so the script should terminate and display an error message, it's terminating but I'm not getting an error message. The information isn't being entered, as I have both $item_title and $image_name set as unique keys in the database table.
Here's the code:
Code:
$item_title = escape_data($_POST['item_title']);
$image = escape_data($_POST['image']);
// Make sure the image title is available.
$query = "SELECT id FROM jodie_pictures
WHERE item_title='$item_title'";
$result = mysql_query ($query) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
// Make sure the image image_name isn't already in the database.
$query = "SELECT id FROM jodie_pictures
WHERE image_name='$image'";
$result = mysql_query ($query) or die(mysql_error());
if (mysql_num_rows($result) == 0)
{
// Max allowed size of the image (in bytes):
$maxUploadSize = 2100000;
--- more code goes here to process image ---
}
else
{ // image_name is already in use
echo "<span style='color:red; font-weight:bold; font-size:16px;'>
ERROR!</span><br /><br />
The image <strong>$image</strong> is already in the database. Hit your "Back" button and choose a new image.<br />";
footer();
exit();
}
}
else
{ // item_title is already in use
echo "<span style='color:red; font-weight:bold; font-size:16px;'>
ERROR!</span><br /><br />
The Picture Title <strong>$item_title</strong> is already in use. Hit your "Back" button and enter a new title.<br />";
footer();
exit();
}
Thanks
Comment