Jump to content

Image not uploading


colleyboy

Recommended Posts

Hi there.

 

I am trying to make a simple script.  I am tryng to make my friend a website so he can add his cars to an online showroom.

 

I.E: one page to add the cars info and upload an image.

then one page to display all the info.

 

I currently have nailed adding the info to the database and showing it in an array but i am having trouble adding an upload box on the form...adding the image info to the db and then showing the image in the info array.

 

This is the code i have:

 

addcar.html *This contains the form to add the vehicle*

 

 

<HTML>

<HEAD>

<TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE>

</HEAD>



<BODY LINK="#000000" ALINK="#000000" VLINK="#000000">

<CENTER><IMG SRC="logo.jpg"></CENTER>



<CENTER>

<TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0">

<TR>

<TD WIDTH="186" valign="top">
<BR>
<CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER>
<CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER>
<CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER>
<CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER>
<CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER>




</TD>

<TD WIDTH="30" valign="top"> </TD>

<TD valign="top">

<FONT SIZE="2" FACE="ARIAL">

<CENTER><IMG SRC="vehicleadd.jpg"><IMG SRC="vehicleedit.jpg"><IMG SRC="vehicledelete.jpg"></CENTER>

<CENTER><B>Add a Vehicle</B></CENTER>
<BR>

<form action="inserts.php" method="post" enctype="multipart/form-data">
<CENTER>Vehicle Name:</CENTER> 
<CENTER><input type="text" name="CarName"></CENTER>
<br>
<CENTER>Vehicle Type:</CENTER>
<CENTER><input type="text" name="CarTitle"></CENTER>
<br>
<CENTER>Vehicle Price:</CENTER>
<CENTER><input type="text" name="CarPrice"></CENTER>
<br>
<CENTER>Vehicle Mileage:</CENTER>
<CENTER><input type="text" name="CarMiles"></CENTER>
<br>
<CENTER>Vehicle Description:</CENTER>
<CENTER><textarea name="CarDescription" rows="10" cols="30"></textarea></CENTER>
<br>
<center>Upload Image</center>
<CENTER><input type="file" name="image_file" /></CENTER>
<BR>

<CENTER><input type="Submit"></CENTER>

</form>

</TD>


</TR>

</TABLE>


<BR><BR><BR><BR>

<CENTER><FONT FACE="VERDANA" SIZE="1">

This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010

</CENTER>
<BR>
<CENTER><A HREF="admin.php">Employee Area</A>

</BODY>

</HTML>

 

inserts.php *This page contains the coding* *Currently adds the data but not image*

 

<HTML>

<HEAD>

<TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE>

</HEAD>



<BODY LINK="#000000" ALINK="#000000" VLINK="#000000">

<CENTER><IMG SRC="logo.jpg"></CENTER>



<CENTER>

<TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0">

<TR>

<TD WIDTH="186" valign="top">
<BR>
<CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER>
<CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER>
<CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER>
<CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER>
<CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER>




</TD>

<TD WIDTH="30" valign="top"> </TD>

<TD valign="top">

<FONT SIZE="2" FACE="ARIAL">

<CENTER><B>Vehicle Added</B></CENTER>
<BR>

<?php

mysql_connect("localhost", "wormste1_barry", "barry") or die(mysql_error());
mysql_select_db("wormste1_barry") or die(mysql_error());

$CarName = mysql_real_escape_string(trim($_POST['CarName']));
$CarTitle = mysql_real_escape_string(trim($_POST['CarTitle']));
$CarPrice = mysql_real_escape_string(trim($_POST['CarPrice']));
$CarMiles = mysql_real_escape_string(trim($_POST['CarMiles']));
$CarDescription = mysql_real_escape_string(trim($_POST['CarDescription']));


if(isset($_POST['submit'])){

//directory in which your file will be uploaded
$target_path = "images/";

$target_path = $target_path . basename( $_FILES['image_file']['name']); 

if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['image_file']['name']). " has been uploaded"; 
//this is file name which you can store in database
$file_name = $_FILES['image_file']['name'];
/*
Code for storing file name into db 
*/
}else
echo "Something went wrong =)";
}


mysql_query("INSERT INTO cars 
(CarName, CarTitle, CarPrice, CarMiles, CarDescription) VALUES('$CarName', '$CarTitle', '$CarPrice', '$CarMiles', '$CarDescription' ) ") 
or die(mysql_error());  


echo "The vehicle data has been added!";

?>


</TD>


</TR>

</TABLE>


<BR><BR><BR><BR>

<CENTER><FONT FACE="VERDANA" SIZE="1">

This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010

</CENTER>
<BR>
<CENTER><A HREF="admin.php">Employee Area</A>

</BODY>

</HTML>

 

 

Just in case: 

 

showroom.php *The page to display the info (Array):

 

<HTML>

<HEAD>

<TITLE>Barry Ottley Motor Co - Quality Used Motors - Stanford-Le-Hope, Essex</TITLE>

</HEAD>



<BODY LINK="#000000" ALINK="#000000" VLINK="#000000">

<CENTER><IMG SRC="logo.jpg"></CENTER>



<CENTER>

<TABLE WIDTH="840" CELLPADDING="0" CELLSPACING="0" BORDER="0">

<TR>

<TD WIDTH="186" valign="top">
<BR>
<CENTER><A HREF="index.html"><IMG SRC="homepage.jpg" alt="Homepage" border="0"></A></CENTER>
<CENTER><A HREF="showroom.php"><IMG SRC="showroom.jpg" alt="Our Online Showroom" border="0"></A></CENTER>
<CENTER><A HREF="location.html"><IMG SRC="ourlocation.jpg" alt="Our location" border="0"></A></CENTER>
<CENTER><A HREF="aboutus.html"><IMG SRC="aboutus.jpg" alt="About Us" border="0"></A></CENTER>
<CENTER><A HREF="contactus.php"><IMG SRC="contactus.jpg" alt="Contact Us" border="0"></A></CENTER>




</TD>

<TD WIDTH="30" valign="top"> </TD>

<TD valign="top">

<FONT SIZE="2" FACE="ARIAL">

<CENTER><B>Current Showroom</B></CENTER>
<BR>

<!-- VIEWING BIT -->

<?php

include('dbconnect.php')

?>


<?php
// Make a MySQL Connection
$query = "SELECT * FROM cars"; 

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
echo "<TABLE CELLPADDING=0 CELLSPACING=0 WIDTH=100% BORDER=0>";
echo "<TR />";
echo "<TD WIDTH=30% VALIGN=TOP />";
echo " <IMG SRC=immg.gif /> ";
echo "<br />";
echo "</TD>";
echo "<TD WIDTH=10 VALIGN=TOP />";
echo " ";
echo "</TD>";
echo "<TD />";

echo "<font size=3 face=arial /><B >";
echo $row['CarPrice'];
echo "</B><font size=2 face=arial />";
echo "<br />";
echo $row['CarTitle'];
echo "<br />";
echo "Vehicle Type: ";
echo $row['CarName'];
echo "<br />";
echo "Vehicle Mileage: ";
echo $row['CarMiles'];
echo "<br />";
echo "Description: ";
echo "<br />";
echo "<br />";
echo $row['CarDescription'];

echo "<br />";
echo "</TD>";


echo "</TR>";
echo "</TABLE>";
echo "<hr WIDTH=100% COLOR=BLACK />";
}
?>

<!-- END OF VIEWING BIT -->

</TD>


</TR>

</TABLE>


<BR><BR><BR><BR>

<CENTER><FONT FACE="VERDANA" SIZE="1">

This website was designed and is hosted by <A HREF="http://www.IRCDirect.co.uk">IRC Direct Website Design™</A> 2010

</CENTER>
<BR>
<CENTER><A HREF="admin.php">Employee Area</A>

</BODY>

</HTML>

 

 

Really could use a helping hand :).

 

Ian

Link to comment
https://forums.phpfreaks.com/topic/213746-image-not-uploading/
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.