Page 1 of 1

PHP MYSQL Images

Posted: Fri Apr 04, 2008 7:29 am
by clarky08
~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


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:

Code: Select all

<?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


~pickle | Please use [ code=html ], [ code=php ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: PHP MYSQL Images

Posted: Fri Apr 04, 2008 8:07 am
by andym01480
I wouldn't store an image in a database - very inefficient use of a database. I'd store the filename instead!

Re: PHP MYSQL Images

Posted: Fri Apr 04, 2008 8:15 am
by clarky08
ok how would i do that??

Re: PHP MYSQL Images

Posted: Fri Apr 04, 2008 10:31 am
by pickle
clarky08 wrote:ok how would i do that??
The filename is just text - store it as text :?

Re: PHP MYSQL Images

Posted: Fri Apr 04, 2008 10:36 am
by palashmaji
test

Re: PHP MYSQL Images

Posted: Fri Apr 04, 2008 10:55 am
by palashmaji
palashmaji wrote:test1