PHP MYSQL Images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
clarky08
Forum Newbie
Posts: 4
Joined: Wed Apr 02, 2008 7:45 am

PHP MYSQL Images

Post 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.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Re: PHP MYSQL Images

Post by andym01480 »

I wouldn't store an image in a database - very inefficient use of a database. I'd store the filename instead!
clarky08
Forum Newbie
Posts: 4
Joined: Wed Apr 02, 2008 7:45 am

Re: PHP MYSQL Images

Post by clarky08 »

ok how would i do that??
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: PHP MYSQL Images

Post by pickle »

clarky08 wrote:ok how would i do that??
The filename is just text - store it as text :?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
palashmaji
Forum Newbie
Posts: 2
Joined: Fri Apr 04, 2008 10:13 am

Re: PHP MYSQL Images

Post by palashmaji »

test
palashmaji
Forum Newbie
Posts: 2
Joined: Fri Apr 04, 2008 10:13 am

Re: PHP MYSQL Images

Post by palashmaji »

palashmaji wrote:test1
Post Reply