Jump to content

PHP MYSQL Images.


clarky08

Recommended Posts

Hi

 

I'm relatively new to PHP and I was just wondering if someone could help me with a problem i'm having. I have the following code:

 

<?php

function myEscape($string)

{

$con = mysql_connect("localhost");

if (!$con)

  {

  die('Could not connect: ' . mysql_error());

  }

 

mysql_select_db("test", $con);

    $var = get_magic_quotes_gpc() ? stripslashes($string) : $string;

    return mysql_real_escape_string($var);

}

 

$cid = myEscape($_GET['cid']);

$cn = myEscape($_GET['cn']);

$cm = myEscape($_GET['cm']);

$sql = "SELECT * FROM `clubs` WHERE `ClubID`='$cid' AND `ClubName`='$cn' AND `ClubManager`='$cm'";

$result = mysql_query($sql) OR DIE (mysql_error());

if (mysql_num_rows($result) > 0)

{

    while ($row = mysql_fetch_array($result))

    {

        echo "<table border='1'>

        <tr>

        <th>Firstname</th>

        <th>Lastname</th>

        </tr>";

        echo "<tr>";

          echo "<td>" . $row['ClubName'] . "</td>";

          echo "<td>" . $row['ClubManager'] . "</td>";

          echo "</tr>";

 

    }

}

else

{

    echo "Houston? We have a problem.";

}

?>         

 

What this is doing for me is getting information from a database using an id that has been set. But i want to be able to have an image for each club too. So my questions are:

 

1) How do you save an image in a database?

 

2) How do you access the image to display it?

 

All help would be much appreciated.

 

Thanks

Colm.

Link to comment
https://forums.phpfreaks.com/topic/99529-php-mysql-images/
Share on other sites

you could also store all your images in one place as yesideez said

 

lets say all the images are in clublogos

 

you can add a field to table for the image name then call the image when you query the club row

 

<img src="clublogos/<?=$row['imagename']?>" />

 

Pretty much like yesideez example but you would have to worry about naming the pictures in the folder. Although his way would keep from duplicate file names. So each has it's ups and downs.

 

Ray

Link to comment
https://forums.phpfreaks.com/topic/99529-php-mysql-images/#findComment-509194
Share on other sites

Just as an extra note I forgot to add in my post, you'd name the images in the "clublogos" folder something like this:

club1.jpg

club2.jpg

club3.jpg

 

and so-on. (I made a typo in my example and used "clud" instead of "club")

 

The only downside to this is that you are restricted to using one type of file, in this case JPEG. Using craygo's method you can use whatever image format you want as you're specifying the entire filename.

Link to comment
https://forums.phpfreaks.com/topic/99529-php-mysql-images/#findComment-509197
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.