Checking for two conditionals - not working

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • DavidPr
    New Member
    • Mar 2007
    • 155

    Checking for two conditionals - not working

    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:
    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 &quot;Back&quot; 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 &quot;Back&quot; button and enter a new title.<br />";
    footer();
    exit();
    }
    Any ideas as to what I'm doing wrong?

    Thanks
  • code green
    Recognized Expert Top Contributor
    • Mar 2007
    • 1726

    #2
    Echo the value of the POST data and test the result of the query.
    Also echo out $query to see what it actually6 says.

    Comment

    • prabirchoudhury
      New Member
      • May 2009
      • 162

      #3
      hey .. query working fine .. find out what 'code_green' said.. check $_POST data ... :)

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #4
        I'm with them.
        Your code looks fine, so the problem must be with the input.

        Maybe your escape_data function is doing something it's not supposed to be doing?

        Comment

        Working...