misstwist Posted May 1, 2007 Share Posted May 1, 2007 HI guys, i feel like a real loser asking this as i've done this may-a-time in the past (all be it a number of years ago) the rest of the site works fine and the last bit i'm trying to do is to get an image to upload, basicaly i have a simple add/edit/delete page, and it does everything it should - except laod the images, all the code i have done does is hard cropy the root directory i put in as a varible. i'd really really appricate a solotuion (FYI the form field and the DB field is called 'image1' (image 2 and 3 i'll add once i get image1 working)) here's the slice of code i'm working on if($mode=="add") { //copy ($_FILES['image1']['tmp_name'], "./images".$_FILES['image1']['name']); $uploaddir = "/home/scootnz/public_html/images"; // Wherethe files to upload to copy($_FILES['image1']['tmp_name'],$uploaddir.$_FILES['image1']['name']); $image1 = $uploaddir.$_FILES['image1']['name']; $Make=$_POST["Make"]; $Model=$_POST["Model"]; $EngineType=$_POST["EngineType"]; $EngineSize=$_POST["EngineSize"]; $Speed=$_POST["Speed"]; $Wheels=$_POST["Wheels"]; $Price=$_POST["Price"]; $Kilometres=$_POST["Kilometres"]; $Year=$_POST["Year"]; $Brakes=$_POST["Brakes"]; $image2=$_POST["image2"]; $image3=$_POST["image3"]; $ShortDes=$_POST["ShortDes"]; $LongDes=$_POST["LongDes"]; $sql="insert into bikes(Make,Model,EngineType,EngineSize,Speed,Wheels,Price,Kilometres,Year,Brakes,image1,image2,image3,ShortDes,LongDes) values('$Make','$Model','$EngineType','$EngineSize','$Speed','$Wheels','$Price','$Kilometres','$Year','$Brakes','$image1','$image2','$image3','$ShortDes','$LongDes')"; $result=mysql_query($sql,$connection) or die(mysql_error()); header("location: indexadmin.php");} Thank guys in advance for your help!! Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/ Share on other sites More sharing options...
Barand Posted May 1, 2007 Share Posted May 1, 2007 Post your form code Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-242974 Share on other sites More sharing options...
misstwist Posted May 1, 2007 Author Share Posted May 1, 2007 ok here is the form: <form name="form1" method="post" action="formsubmit.php?mode=add"> <br> <TABLE width="75%" align="center" class="imagebox55"> <TR> <TD colspan="2"><P class="header" align="center"><b>Upload New Scooter </b></P><p class="menu" align="right">*required fields</p></TD> </TR> <TR> <TD><p class="normal2">Make*</p></TD> <TD> <select name="Make"> <option value="Vespa">Vespa</option> <option value="Piaggio">Piaggio</option> <option value="TGB">TGB</option> <option value="Peagout">Peagout</option> </select></TD> </TR> <tr> <td height="37"> <p class="normal2">Model*</p></td> <td><INPUT TYPE="text" NAME="Model"></td> </tr> <tr> <td><p class="normal2">Engine Size*</p></td> <td><INPUT TYPE="text" NAME="EngineSize"></td> </tr> <tr> <tr> <td><p class="normal2">Engine Type*</p></td> <td><input type="text" name="EngineType"></td> </tr> <tr> <tr> <td><p class="normal2">Speed*</p></td> <td><INPUT TYPE="text" NAME="Speed"></td> </tr> <tr> <tr> <td><p class="normal2">Wheels</p></td> <td><INPUT TYPE="text" NAME="Wheels"></td> </tr> <tr> <tr> <td><p class="normal2">Brakes</p></td> <td><INPUT TYPE="text" NAME="Brakes"></td> </tr> <tr> <td><p class="normal2">Year</p></td> <td><INPUT TYPE="text" NAME="Year"></td> </tr> <tr> <td><p class="normal2">Kilometres</p></td> <td width=81%><INPUT TYPE="text" NAME="Kilometres"></td> </tr> <tr> <td><br><br><br><p class="normal2">Image 1</p></td> <td><p class="menu">Please insure images are 300x300 pixels</p><br><input type="file" name="image1" size="30"></td> </tr> <tr> <td><p class="normal2">Image 2</p></td> <td><input type="file" name="image2" size="30"></td> </tr> <tr> <td><p class="normal2">Image 3</p></td> <td><input type="file" name="image3" size="30"></td> </tr> <tr> <td><p class="normal2">Short Description - up to 100 Characters</p></td> <td><textarea name="ShortDes" cols="50" rows="2"></textarea></td> </tr> <tr> <td><p class="normal2">Details - up to 250 Characters</p></td> <td><textarea name="LongDes" cols="50" rows="4"></textarea></td> </tr> <td><p class="normal2">Price (NZD)$*</p></td> <td><INPUT TYPE="text" NAME="Price" size="7"></td> </tr> </TABLE> <input type="submit" name="submit2" value="Save Data" class="header"> <INPUT TYPE="RESET" VALUE="Reset"> </FORM> Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-242982 Share on other sites More sharing options...
Barand Posted May 1, 2007 Share Posted May 1, 2007 If you are uploading files the form tag needs to include enctype='multipart/form-data' Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-242986 Share on other sites More sharing options...
john010117 Posted May 1, 2007 Share Posted May 1, 2007 <form name="form1" method="post" enctype="multipart/form-data" action="formsubmit.php?mode=add"> Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-242990 Share on other sites More sharing options...
misstwist Posted May 2, 2007 Author Share Posted May 2, 2007 hi guys, thanks for that i've now added that but the script on the other page is still not working, and now adds nothing to the DB, any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-243137 Share on other sites More sharing options...
Barand Posted May 2, 2007 Share Posted May 2, 2007 try if($_GET['mode']=="add") { Quote Link to comment https://forums.phpfreaks.com/topic/49563-urgent-problem-with-image-upload-script-should-be-simple-for-someone/#findComment-243250 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.