img script works great but almost duplicate of the code does not

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • tolkienarda
    Contributor
    • Dec 2006
    • 316

    img script works great but almost duplicate of the code does not

    hi all

    i have a problem i have a script that i got working exactly the way i wanted it. and then i tried to intrigate it into the site and it totaly stopped working. below is the original code

    [PHP]
    <?
    $host="localhos t"; // Host name.
    $db_user="****" ; // MySQL username.
    $db_password="* ******"; // MySQL password.
    $database="cms" ; // Database name.
    $cms = mysql_pconnect( $host, $db_user, $db_password) or trigger_error(m ysql_error(),E_ USER_ERROR);
    mysql_select_db ($database, $cms);
    $errmsg="";

    // If this is the image request, send out the image
    $page = "home";
    $position = $_REQUEST[gim];
    $locationval = $page . $position;
    $gotten = mysql_query("SE LECT * FROM pix WHERE location='$loca tionval'");
    if ($row = mysql_fetch_ass oc($gotten))
    {
    $bytes = $row[imgdata];
    header("Content-type: image/jpeg");
    print $bytes;
    exit ();
    }
    ?>

    <html><head>
    <title>Upload image</title>
    <table>
    <tr>
    <td><img src=?gim=1 width="144" /></td>
    </tr>
    <tr>
    <td>
    <form enctype='multip art/form-data' action='uploade r.php' method='post'>
    <input type='hidden' name='MAX_FILE_ SIZE' value='150000'>
    <input type='hidden' name='completed ' value='submitte d'>
    <input type='file' name='imagefile '>
    <input type="hidden" name="location" value="home1">< br>
    <input type='submit'>
    </form>
    </td>
    </tr>
    <tr>
    <td><img src=?gim=2 width=144></td>
    </tr>
    <tr>
    <td>
    <form enctype='multip art/form-data' action='uploade r.php' method='post'>
    <input type='hidden' name='MAX_FILE_ SIZE' value='150000'>
    <input type='hidden' name='completed ' value='submitte d'>
    <input type='file' name='imagefile '><br>
    <input type="hidden" name="location" value="home2">< br>
    <input type='submit' value="submit">
    </form>
    </td>
    </tr>
    </table>



    </body>
    </html>

    [/PHP]

    ok so the basic thought behind this is i send the number with my image tag and then that concatinates that with the name of the page and searches for the image that belongs with that location. so prety simple, the above script works but the one below one has just a small peice of php in addition to the rest of code above. but there is apparently some conflict that i cannot figure out.

    [PHP]
    <?
    $host="localhos t"; // Host name.
    $db_user="****" ; // MySQL username.
    $db_password="* ******"; // MySQL password.
    $database="cms" ; // Database name.
    $cms = mysql_pconnect( $host, $db_user, $db_password) or trigger_error(m ysql_error(),E_ USER_ERROR);
    mysql_select_db ($database, $cms);
    $errmsg="";

    // If this is the image request, send out the image
    $page = "home";
    $position = $_REQUEST[gim];
    $locationval = $page . $position;
    $gotten = mysql_query("SE LECT * FROM pix WHERE location='$loca tionval'");
    $in = 'not in';
    if ($imgrow = mysql_fetch_ass oc($gotten))
    {
    $bytes = $imgrow[imgdata];
    header("Content-type: image/jpeg");
    $in = 'in';
    print $bytes;
    exit ();
    }
    ?>
    </head>

    <body>
    <img src=?gim=1 width="144">
    <table width='650' border='1'>
    <tr>
    <td><img src="images/header.jpg" width="650" height="88"></td>
    </tr>
    <tr>
    <td>
    <table width="100%" border='1'>
    <tr>
    <td width="25%"><im g src="../images/image1.jpg"></td>
    <td colspan="2">
    <form action="scripts/update.php" method="post">
    <input type='text' name='hometxt1t itle'>
    <input type="text" name='hometxt1a uthor'>
    <textarea name='hometxt1t xt' rows='5' cols="70">

    <?

    $result=mysql_q uery("SELECT id, title, author, article, location FROM atricles");
    $row=mysql_num_ rows($result);
    $row2 = mysql_fetch_row ($result);
    echo $row2[3];
    ?>

    </textarea>
    <input type="hidden" name='location' value='home1'>
    <br />
    <input type="submit">
    </form>
    </td>
    </tr>
    <tr>
    <td colspan="2">
    <img src=?gim=1 width="144"><br >
    <form enctype='multip art/form-data' action='uploade r.php' method='post'>
    <input type='hidden' name='MAX_FILE_ SIZE' value='150000'>
    <input type='hidden' name='completed ' value='submitte d'>
    <input type='file' name='imagefile '>
    <input type="hidden" name="location" value="home1">< br>
    <input type='submit'>
    </form>
    </td>
    <td width="25%"><im g src="../images/image3.jpg"></td>
    </tr>
    </table>

    </td>
    </tr>
    <tr>
    <td><img src="images/footer.jpg" width="650" height="125"></td>
    </tr>
    </table>
    <?
    echo $in, '<br>', $page, '<br>', $position, '<br>', $locationval;
    ?>

    </body>
    </html>
    [/PHP]

    and because of my tests i know that i am not getting into my if statement
    thanks

    eric
  • ronverdonk
    Recognized Expert Specialist
    • Jul 2006
    • 4259

    #2
    So what is the difference or do we have to puzzle that out?

    Ronald :cool:

    Comment

    • tolkienarda
      Contributor
      • Dec 2006
      • 316

      #3
      um i am not sure what you mean but i will try to explain. the first script is somthing i built just to develop the code i needed to upload and display images. the second script is where i actualy need it to be. the main difference on the second script is there is a second form that allows people to change an atricle. but the code that deals with the image is copy and pasted from the previous page so i don't know what is happening here i think that maybe there is some conflict between my article form and my image script

      eric

      Comment

      • tolkienarda
        Contributor
        • Dec 2006
        • 316

        #4
        ok i just found the solution but i have no idea why it matters. what i did is move my php code to above my dtd and it fixed it. now i thought that the location of the php didn't matter but maybe i was wrong if you know why it matterd could you reply with the reason

        eric

        Comment

        Working...