Okay, that makes a lot more sense now here is the code for the gallery upload
<?php
// Connect to database
$errmsg = "";
if (! @mysql_connect("localhost","Knotty","letmein")) {
$errmsg = "Cannot connect to database";
}
@mysql_select_db("rudeboy");
if ($_REQUEST[completed] == 1) {
// Need to add - check for large upload. Otherwise the code
// will just duplicate old file ;-)
// ALSO - note that latest.img must be public write and in a
// live appliaction should be in another (safe!) directory.
move_uploaded_file($_FILES['imagefile']['tmp_name'],"latest.img");
$instr = fopen("latest.img","rb");
$image = addslashes(fread($instr,filesize("latest.img")));
if (strlen($instr) < 149000) {
mysql_query ("insert into pix (title, imgdata) values (\"".
$_REQUEST[whatsit].
"\", \"".
$image.
"\")");
} else {
$errmsg = "Too large!";
}
}
// Find out about latest image
$gotten = @mysql_query("select * from pix order by pid desc limit 1");
if ($row = @mysql_fetch_assoc($gotten)) {
$title = htmlspecialchars($row[title]);
$bytes = $row[imgdata];
} else {
$errmsg = "There is no image in the database yet";
$title = "no database image available";
}
// If this is the image request, send out the image
if ($_REQUEST[gim] == 1) {
header("Content-type: image/jpeg");
print $bytes;
exit ();
}
?>
This part of it works fine, although I need to change the way it connects to the database, I don't like the idea of having login details on each page, as I mentioned earlier ideally I want to have an include at the top of the script that points to location of the login details, this would also mean that I don't have to change all the script if I changed any of the login information.
So the database connection part at the top need to be changed to
include('includes/db.php');
which points to this script with all the login details.
<?php
$db_link = mysql_connect('localhost', 'Knotty' , 'letmein');
if (!db_link)
{
echo 'error connnecting to database.';
exit;
}
if (!mysql_select_db('rudeboy',$db_link))
{
echo 'error connnecting to database.';
exit;
}
?>
After the image details have been stored in the database, I would like to be able to display all the images on another page by simply querying the database and then looping through all of it.
something a bit like this.
<?php
$query = 'SELECT * FROM pix'
$result = mysql_query($query, $db_link);
while ($row = mysql_fetch_assoc($result))
{
?>
<img src=?gim=1 width=144>
<?= $title ?>
<?php
}
?>
but I've had no luck solving either of these two problems
Thanks for the help!