Results 1 to 3 of 3

Thread: how I do this

  1. #1
    Join Date
    Oct 2008
    Posts
    50
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how I do this

    I want to make a connection between a photo a web site and a database. How can I put a image on an database(mysql)?What is the code that make all this connection!!!! pls help!!!

  2. #2
    Join Date
    Jul 2006
    Location
    just north of Boston, MA
    Posts
    1,806
    Thanks
    13
    Thanked 72 Times in 72 Posts

    Default

    dont store the actual image in the database, but rather save a reference to the image via a url, then query out the url and use that in the image.

  3. #3
    Join Date
    Sep 2008
    Location
    Bristol - UK
    Posts
    842
    Thanks
    32
    Thanked 132 Times in 131 Posts

    Default

    To connect to a MySQL database you need something to connect to it, in this case I'll use PHP but you can do it in other ways:

    PHP Code:
    <?php

    $host 
    "host"// Host server name here
    $user "user"// The username your host gives you to connect to the database
    $pass "pass" // The password your host gives you


    $con mysql_connect($host$user$pass)

    if(!
    $con)

      die(
    "Failed to connect to the server" mysql_error());
    }

    // Code for selecting the database follows

    ?>
    You need to know the name of your database to connect to it, and what tables you're going to access.

    But as boogyman says, just save the url as a string like so:

    PHP Code:
    <?php

    $image 
    "images/flyers/advert.jpg";

    $result mysql_query("SELECT * FROM table WHERE image = $image");
    while(
    $row mysql_fetch_array($result))
    {
    echo  
    $row['image'];

    }

    ?>

Bookmarks

Posting Permissions

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