Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New Coder
    Join Date
    Dec 2003
    Location
    texas
    Posts
    96
    Thanks
    1
    Thanked 0 Times in 0 Posts

    A simple select statement, but I have an error...

    I have a select statement that gets an ID from the URL, with this ID I want it to select an image from a database, or the code for the image so it will be displayed can someone tell me what is wrong with my code.

    <?
    //-----------------------------------
    //this is the connection string to connect to the database
    //-----------------------------------
    $db = mysql_connect("localhost", "username", "password") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());


    //----------------------------------------------
    // Get the ID from the URL, or supply a default.
    //----------------------------------------------
    $id = (isset($_GET["id"])) ? $_GET["id"] : "1";
    //-----------------------------------
    // This is display the image...
    //-----------------------------------
    $query2 = "SELECT images FROM Image WHERE id='$id'";
    $result2 = mysql_query($query2) or die(mysql_error());
    ?>

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <? echo($query2);?>
    Put the image here get it from the url
    <input type="button" onClick="window.close()" value="Close Window">
    </body>
    </html>

    If I put query2 in the echo statement then it displays the actual select statement

    If I put result2 in the echo statement then it displays resource ID#3, but I think my problem is my select statement, can someone help please?
    thanks
    bri

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Location
    Philadelphia
    Posts
    241
    Thanks
    2
    Thanked 5 Times in 5 Posts
    First off... are your echoing the query not the result

    Secondly, you need to run a while statement to pull the stuff u need out the DB


    *Edit Well you see ur first problem, try running a while statement and make sure you put the html stuff to turn the links from the DB into actual pics, thats what ur doing rite?

  • #3
    Regular Coder dniwebdesign's Avatar
    Join Date
    Dec 2003
    Location
    Carrot River, Saskatchewan
    Posts
    842
    Thanks
    15
    Thanked 9 Times in 9 Posts
    Please place your code in [ php ] and [ /php ] tags... (without the spaces)... Then we can read the code better and easier and might be able to help you.
    Dawson Irvine
    CEO - DNI Web Design
    http://www.dniwebdesign.com

  • #4
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,265
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    <?php
    //-----------------------------------
    //this is the connection string to connect to the database
    //-----------------------------------
    $db mysql_connect("localhost""username""password") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());


    //----------------------------------------------
    // Get the ID from the URL, or supply a default.
    //----------------------------------------------
    $id = (isset($_GET["id"])) ? $_GET["id"] : "1";
    //-----------------------------------
    // This is display the image...
    //-----------------------------------
    $query2 "SELECT images FROM Image WHERE id='$id'";
    $result2 mysql_query($query2) or die(mysql_error());

    $image mysql_fetch_assoc($result2);
    ?>

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php echo $image['images'];?>
    Put the image here get it from the url
    <input type="button" onClick="window.close()" value="Close Window">
    </body>
    </html>
    Should work

  • #5
    New to the CF scene
    Join Date
    Sep 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Nightfire
    PHP Code:
    <?php
    //-----------------------------------
    //this is the connection string to connect to the database
    //-----------------------------------
    $db mysql_connect("localhost""username""password") or die(mysql_error());
    mysql_select_db("table") or die(mysql_error());


    //----------------------------------------------
    // Get the ID from the URL, or supply a default.
    //----------------------------------------------
    $id = (isset($_GET["id"])) ? $_GET["id"] : "1";
    //-----------------------------------
    // This is display the image...
    //-----------------------------------
    $query2 "SELECT images FROM Image WHERE id='$id'";
    $result2 mysql_query($query2) or die(mysql_error());

    $image mysql_fetch_assoc($result2);
    ?>

    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    </head>

    <body>
    <?php echo $image['images'];?>
    Put the image here get it from the url
    <input type="button" onClick="window.close()" value="Close Window">
    </body>
    </html>
    Should work
    Yup! This should works.


    Paul

    We Make IT Simple!
    Email: paul@niveux.net
    Last edited by paulsiew; 09-27-2004 at 06:59 PM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •