corsasport.co.uk
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Help pleeeeez!


New Topic

New Poll
  Subscribe | Add to Favourites

You are not logged in and may not post or reply to messages. Please log in or create a new account or mail us about fixing an existing one - register@corsasport.co.uk

There are also many more features available when you are logged in such as private messages, buddy list, location services, post search and more.


Author PHP Help pleeeeez!
liamC
Member

Registered: 28th Feb 04
User status: Offline
2nd Mar 07 at 01:46   View User's Profile U2U Member Reply With Quote

OK, I have set up a PHP/MYSQL Database to add cars to a database. Each car added by the user comes with an image of said vehicle, which the user uploads from their machine along with the cars make/model/etc.

I have got the database description fields of the vehicle adding to the database 100% successfully.

I have also got the images uploading to my webspace successfully. This is also working 100%.

What I want however, is when the image is uploaded, to somehow put the address to the image into a database field alongside the rest of the row of details of the vehicle, so when the user wants to view that vehicle, I can just echo out the image URL to go alongside all of the rest of the vehicles details. [Hope this makes sense!]

I have pasted my code below to see if anyone can help out? I have already added another field to the database called fldIMG where I would like the URL of the uploaded image to go to. The below is all the code I have which successfully adds all the required info.

Any help appreciated

code:
<?php

// Read values from form using $_POST (safest)

$fldMAKE=$_POST["fldMAKE"];
$fldMODEL=$_POST["fldMODEL"];
$fldENGINE=$_POST["fldENGINE"];
$fldPRICE=$_POST["fldPRICE"];
$fldMILEAGE=$_POST["fldMILEAGE"];
$fldYEAR=$_POST["fldYEAR"];
$fldCOLOUR=$_POST["fldCOLOUR"];
$fldDESC=$_POST["fldDESC"];

// Connect to server
// Replace username and password by your details

$db = @mysql_connect("dbname.domainname.com","username","password");
if (!$db)
{
do_error("Could not connect to the server");
}


// Connect to the database
// Note that your database will be called username

@mysql_select_db("usedcars",$db)or do_error("Could not connect to the database");

// Run query

$sql="INSERT INTO tblUSEDCARS (fldMAKE,fldMODEL,fldENGINE,fldPRICE,fldMILEAGE,fldYEAR,fldCOLOUR,fldDESC) values ('$fldMAKE','$fldMODEL','$fldENGINE','$fldPRICE','$fldMILEAGE','$fldYEAR','$fldCOLOUR','$fldDESC')";

if (mysql_query($sql,$db))
{
echo "Vehicle has been added to the database.<p>";
}
else
{
do_error("Failed to add record");
}

function do_error($error)
{
echo $error;
die;
}

?>
<?php
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
echo "Uploading " . $_FILES["file"]["name"];
echo " (" . $_FILES["file"]["type"] . ", ";
echo ceil($_FILES["file"]["size"] / 1024) . " Kb).<br />";
echo "File is temporarily stored as " . $_FILES["file"]["tmp_name"];
?>
<?php
if (($_FILES['file']['type'] == 'image/gif') &&
($_FILES['file']['size'] < 5000))
{
echo 'Return Code: ' . $_FILES['file']['error'] . '<br />';
echo 'Uploading ' . $_FILES['file']['name'] . ' (' .
$_FILES['file']['type'] . ', ' .
ceil($_FILES['file']['size'] / 1024) . ' Kb).<br />';

if (file_exists('../images/usedcars/' . $_FILES['file']['name']))
{
echo $_FILES['file']['name'] . ' already exists. ';
echo 'Please delete the destination file and try again.';
}
else
{
move_uploaded_file($_FILES['file']['tmp_name'],
'../images/usedcars/' . $_FILES['file']['name']);
echo 'File has been stored in your uploads directory.';
}
} else
{
echo 'Sorry, we only accept .gif images under 5Kb for upload.';
}
?>


[Edited on 02-03-2007 by liamC]
Ian
Site Administrator

Avatar

Registered: 28th Aug 99
Location: Liverpool
User status: Offline
2nd Mar 07 at 02:02   View Garage View User's Profile U2U Member Reply With Quote

Can you not just make a variable and put in it the basic web address, then add on the filename?

Or even just store filename and sort the path out when you print the image tag?

You have all the necessary information when it is uploaded.
liamC
Member

Registered: 28th Feb 04
User status: Offline
2nd Mar 07 at 02:08   View User's Profile U2U Member Reply With Quote

Which one do you recommend Ian out of the 2 you've suggested?

Easiest ideally, as I'm a relatively n00by newbie!

[Edited on 02-03-2007 by liamC]
AndyKent
Member

Registered: 3rd Sep 05
User status: Offline
2nd Mar 07 at 09:07   View User's Profile U2U Member Reply With Quote

You've already got the line "../images/usedcars/' . $_FILES['file']['name']);"

Just insert this into the database and echo it out when you want the image to be displayed.

Thats the easiest....

[Edited on 02-03-2007 by aPk]

 
New Topic

New Poll

  Related Threads Author Forum Replies Views Last Post
Few Pics from the Pod (56K Warning) PaulW General Chat 12 1064
21st Feb 05 at 16:40
by Jambo
 
Photoshop request 1 SCR Snap Day 5 367
26th Jun 06 at 08:49
by 1 SCR
 
Dodgy HTML/PHP/Table problem liamC Geek Day 9 783
24th Jan 07 at 19:37
by liamC
 
phpbb index Tom J Geek Day 3 775
13th Feb 07 at 15:34
by Steve
 

Corsa Sport » Message Board » Off Day » Geek Day » PHP Help pleeeeez! 28 database queries in 0.0121851 seconds