dewey_witt Posted July 4, 2007 Share Posted July 4, 2007 OK Im on a deadline here. Last script for the site. Im stuck. Literaly. I have a form that i need to add an image upload element to. What i need is to upload the image to the server, and store the image name in mysql database. Im semi new to php. all my other scripts have worked I don't know what Im doing wrong. Well ok here if the php code. WARNING THIS IS A HUGE CODE! LOL But realy pleeeeeeeeease Helppppppp! OK this is the php for the form without the image upload: <?php if (!isset($_SESSION)) { session_start(); } //Check to see if all the data was entered and return them to the page if not. if ((!$_POST['StrAddy']) || (!$_POST['City']) || (!$_POST['County']) || (!$_POST['State']) || (!$_POST['Suburb']) || (!$_POST['SubDiv']) || (!$_POST['Lst_Price']) || (!$_POST['Total_Rooms']) || (!$_POST['Bedrooms']) || (!$_POST['Baths']) || (!$_POST['FamilyRoom']) || (!$_POST['FormalDining']) || (!$_POST['First_Bedroom']) || (!$_POST['First_Bath']) || (!$_POST['Type']) || (!$_POST['Levels']) || (!$_POST['Arch']) || (!$_POST['Const']) || (!$_POST['Found']) || (!$_POST['Roof']) || (!$_POST['Windows']) || (!$_POST['Heat']) || (!$_POST['Cooling']) || (!$_POST['Age']) || (!$_POST['New']) || (!$_POST['Lot']) || (!$_POST['Acreage']) || (!$_POST['Basement']) || (!$_POST['Garage']) || (!$_POST['Parking']) || (!$_POST['Fireplace']) || (!$_POST['Gas']) || (!$_POST['Water']) || (!$_POST['Sewer']) || (!$_POST['Zoning']) || (!$_POST['SaTax']) || (!$_POST['TaxRate']) || (!$_POST['Asmnt']) || (!$_POST['Occupy']) || (!$_POST['Transp']) || (!$_POST['LvlCondo']) || (!$_POST['HOA']) || (!$_POST['SchoolDis']) || (!$_POST['SchoolPhone']) || (!$_POST['OhDate']) || (!$_POST['OhTime']) || (!$_POST['Auction']) || (!$_POST['TaxID']) || (!$_POST['SpecFin']) || (!$_POST['Comments']) || (!$_POST['FullName']) || (!$_POST['ListerComp']) || (!$_POST['CompCity']) || (!$_POST['CompState']) || (!$_POST['CompZip']) || (!$_POST['PrimPhone']) || (!$_POST['OfficePhone']) || (!$_POST['PrimFax']) || (!$_POST['Cell']) || (!$_POST['ListerEmail'])) { // you will probably want to modify this - if you just send the user back to the page they were // on without telling them they were missing some information, they won't know that their // record wasn't saved. This is bad form! header("Location: http://www.ezsellnow.com/Post_Listings.php"); echo "It seems you have missed a feild or more. Please Check your Information Carefully"; exit; } // only save the information if this page was accessed with POST information if (isset($_POST)) { //Create a variable to hold the database name. $db_name="db_name"; //create a variable to hole the database name. $table_name="Post"; //Add the conection information. $connection= mysql_connect("Server", "username", "password")or die(mysql_error()); //Select the database $db = mysql_select_db($db_name, $connection) or die(mysql_error()); //Create the sql statement. $sql= "INSERT INTO $table_name(StrAddy, City, County, State, Suburb, SubDiv, Lst_Price, Total_Rooms, Bedrooms, Baths, FamilyRoom, FormalDining, First_Bedroom, First_Bath, Type, Levels, Arch, Const, Found, Roof, Windows, Heat, Cooling, Age, New, Lot, Acreage, Basement, Garage, Parking, Fireplace, Gas, Water, Sewer, Zoning, SaTax, TaxRate, Asmnt, Occupy, Transp, LvlCondo, HOA, SchoolDis, SchoolPhone, OhDate, OhTime, Auction, TaxID, SpecFin, Comments, FullName, ListerComp, CompAddy, CompCity, CompState, CompZip, PrimPhone, OfficePhone, PrimFax, Cell, ListerEmail) Values ('" . $_POST['StrAddy'] . "', '" . $_POST['City'] . "', '" . $_POST['County'] . "', '" . $_POST['State'] . "', '" . $_POST['Suburb'] . "', '" . $_POST['SubDiv'] . "', '" . $_POST['Lst_Price'] . "', '" . $_POST['Total_Rooms'] . "', '" . $_POST['Bedrooms'] . "', '" . $_POST['Baths'] . "', '" . $_POST['FamilyRoom'] . "', '" . $_POST['FormalDining'] . "', '" . $_POST['First_Bedroom'] . "', '" . $_POST['First_Bath'] . "', '" . $_POST['Type'] . "', '" . $_POST['Levels'] . "', '" . $_POST['Arch'] . "', '" . $_POST['Const'] . "', '" . $_POST['Found'] . "', '" . $_POST['Roof'] . "', '" . $_POST['Windows'] . "', '" . $_POST['Heat'] . "', '" . $_POST['Cooling'] . "', '" . $_POST['Age'] . "', '" . $_POST['New'] . "', '" . $_POST['Lot'] . "', '" . $_POST['Acreage'] . "', '" . $_POST['Basement'] . "', '" . $_POST['Garage'] . "', '" . $_POST['Parking'] . "', '" . $_POST['Fireplace'] . "', '" . $_POST['Gas'] . "', '" . $_POST['Water'] . "', '" . $_POST['Sewer'] . "', '" . $_POST['Zoning'] . "', '" . $_POST['SaTax'] . "', '" . $_POST['TaxRate'] . "', '" . $_POST['Asmnt'] . "', '" . $_POST['Occupy'] . "', '" . $_POST['Transp'] . "', '" . $_POST['LvlCondo'] . "', '" . $_POST['HOA'] . "', '" . $_POST['SchoolDis'] . "', '" . $_POST['SchoolPhone'] . "', '" . $_POST['OhDate'] . "', '" . $_POST['OhTime'] . "', '" . $_POST['Auction'] . "', '" . $_POST['TaxID'] . "', '" . $_POST['SpecFin'] . "', '" . $_POST['Comments'] . "', '" . $_POST['FullName'] . "', '" . $_POST['ListerComp'] . "', '" . $_POST['CompAddy'] . "', '" . $_POST['CompCity'] . "', '" . $_POST['CompState'] . "', '" . $_POST['CompZip'] . "', '" . $_POST['PrimPhone'] . "', '" . $_POST['OfficePhone'] . "', '" . $_POST['PrimFax'] . "', '" . $_POST['Cell'] . "', '" . $_POST['ListerEmail'] . "')"; //Create a variable to hold the result of the query. $result = mysql_query($sql, $connection) or die(mysql_error()); //Show a success Message. if ($result) { echo "SUCCESS - your record was saved."; // you might just want to redirect them here and only warn them if there was an error } else { echo "OOPS - there has been an error. Please Try Again" . mysql_error(); } } //Close PHP block. ?> OK Now again I need to upload a photo to server and record the pic name in this db. please help! Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 4, 2007 Share Posted July 4, 2007 hmm there is an awful lot of OR in your logic <?php $check = true; foreach($_POST as $key => $val) { if (empty($val)) { $check = false; break; } } if ((bool)$check == false) { echo "It seems you have missed a feild or more. Please Check your Information Carefully"; exit; } ?> as for the upload script - I can't really decipher what is going on in there as it is a mess and you didn't use the code tags on the post. where exactly is the code to perform the upload??? or have I got the wrong end of the stick??? Quote Link to comment Share on other sites More sharing options...
dewey_witt Posted July 4, 2007 Author Share Posted July 4, 2007 The code to preform the upload isnt on here. this is the code for all the other feilds. I need to intergrate the other code into this. I have tried a gazzilion methods......... none worked. and sorry for not useing the color coding I'm New here :/ <?php if (!isset($_SESSION)) { session_start(); } //Check to see if all the data was entered and return them to the page if not. if ((!$_POST['StrAddy']) || (!$_POST['City']) || (!$_POST['County']) || (!$_POST['State']) || (!$_POST['Suburb']) || (!$_POST['SubDiv']) || (!$_POST['Lst_Price']) || (!$_POST['Total_Rooms']) || (!$_POST['Bedrooms']) || (!$_POST['Baths']) || (!$_POST['FamilyRoom']) || (!$_POST['FormalDining']) || (!$_POST['First_Bedroom']) || (!$_POST['First_Bath']) || (!$_POST['Type']) || (!$_POST['Levels']) || (!$_POST['Arch']) || (!$_POST['Const']) || (!$_POST['Found']) || (!$_POST['Roof']) || (!$_POST['Windows']) || (!$_POST['Heat']) || (!$_POST['Cooling']) || (!$_POST['Age']) || (!$_POST['New']) || (!$_POST['Lot']) || (!$_POST['Acreage']) || (!$_POST['Basement']) || (!$_POST['Garage']) || (!$_POST['Parking']) || (!$_POST['Fireplace']) || (!$_POST['Gas']) || (!$_POST['Water']) || (!$_POST['Sewer']) || (!$_POST['Zoning']) || (!$_POST['SaTax']) || (!$_POST['TaxRate']) || (!$_POST['Asmnt']) || (!$_POST['Occupy']) || (!$_POST['Transp']) || (!$_POST['LvlCondo']) || (!$_POST['HOA']) || (!$_POST['SchoolDis']) || (!$_POST['SchoolPhone']) || (!$_POST['OhDate']) || (!$_POST['OhTime']) || (!$_POST['Auction']) || (!$_POST['TaxID']) || (!$_POST['SpecFin']) || (!$_POST['Comments']) || (!$_POST['FullName']) || (!$_POST['ListerComp']) || (!$_POST['CompCity']) || (!$_POST['CompState']) || (!$_POST['CompZip']) || (!$_POST['PrimPhone']) || (!$_POST['OfficePhone']) || (!$_POST['PrimFax']) || (!$_POST['Cell']) || (!$_POST['ListerEmail'])) { // you will probably want to modify this - if you just send the user back to the page they were // on without telling them they were missing some information, they won't know that their // record wasn't saved. This is bad form! header("Location: http://www.ezsellnow.com/Post_Listings.php"); echo "It seems you have missed a feild or more. Please Check your Information Carefully"; exit; } // only save the information if this page was accessed with POST information if (isset($_POST)) { //Create a variable to hold the database name. $db_name="db_name"; //create a variable to hole the database name. $table_name="Post"; //Add the conection information. $connection= mysql_connect("Server", "username", "password")or die(mysql_error()); //Select the database $db = mysql_select_db($db_name, $connection) or die(mysql_error()); //Create the sql statement. $sql= "INSERT INTO $table_name(StrAddy, City, County, State, Suburb, SubDiv, Lst_Price, Total_Rooms, Bedrooms, Baths, FamilyRoom, FormalDining, First_Bedroom, First_Bath, Type, Levels, Arch, Const, Found, Roof, Windows, Heat, Cooling, Age, New, Lot, Acreage, Basement, Garage, Parking, Fireplace, Gas, Water, Sewer, Zoning, SaTax, TaxRate, Asmnt, Occupy, Transp, LvlCondo, HOA, SchoolDis, SchoolPhone, OhDate, OhTime, Auction, TaxID, SpecFin, Comments, FullName, ListerComp, CompAddy, CompCity, CompState, CompZip, PrimPhone, OfficePhone, PrimFax, Cell, ListerEmail) Values ('" . $_POST['StrAddy'] . "', '" . $_POST['City'] . "', '" . $_POST['County'] . "', '" . $_POST['State'] . "', '" . $_POST['Suburb'] . "', '" . $_POST['SubDiv'] . "', '" . $_POST['Lst_Price'] . "', '" . $_POST['Total_Rooms'] . "', '" . $_POST['Bedrooms'] . "', '" . $_POST['Baths'] . "', '" . $_POST['FamilyRoom'] . "', '" . $_POST['FormalDining'] . "', '" . $_POST['First_Bedroom'] . "', '" . $_POST['First_Bath'] . "', '" . $_POST['Type'] . "', '" . $_POST['Levels'] . "', '" . $_POST['Arch'] . "', '" . $_POST['Const'] . "', '" . $_POST['Found'] . "', '" . $_POST['Roof'] . "', '" . $_POST['Windows'] . "', '" . $_POST['Heat'] . "', '" . $_POST['Cooling'] . "', '" . $_POST['Age'] . "', '" . $_POST['New'] . "', '" . $_POST['Lot'] . "', '" . $_POST['Acreage'] . "', '" . $_POST['Basement'] . "', '" . $_POST['Garage'] . "', '" . $_POST['Parking'] . "', '" . $_POST['Fireplace'] . "', '" . $_POST['Gas'] . "', '" . $_POST['Water'] . "', '" . $_POST['Sewer'] . "', '" . $_POST['Zoning'] . "', '" . $_POST['SaTax'] . "', '" . $_POST['TaxRate'] . "', '" . $_POST['Asmnt'] . "', '" . $_POST['Occupy'] . "', '" . $_POST['Transp'] . "', '" . $_POST['LvlCondo'] . "', '" . $_POST['HOA'] . "', '" . $_POST['SchoolDis'] . "', '" . $_POST['SchoolPhone'] . "', '" . $_POST['OhDate'] . "', '" . $_POST['OhTime'] . "', '" . $_POST['Auction'] . "', '" . $_POST['TaxID'] . "', '" . $_POST['SpecFin'] . "', '" . $_POST['Comments'] . "', '" . $_POST['FullName'] . "', '" . $_POST['ListerComp'] . "', '" . $_POST['CompAddy'] . "', '" . $_POST['CompCity'] . "', '" . $_POST['CompState'] . "', '" . $_POST['CompZip'] . "', '" . $_POST['PrimPhone'] . "', '" . $_POST['OfficePhone'] . "', '" . $_POST['PrimFax'] . "', '" . $_POST['Cell'] . "', '" . $_POST['ListerEmail'] . "')"; //Create a variable to hold the result of the query. $result = mysql_query($sql, $connection) or die(mysql_error()); //Show a success Message. if ($result) { echo "SUCCESS - your record was saved."; // you might just want to redirect them here and only warn them if there was an error } else { echo "OOPS - there has been an error. Please Try Again" . mysql_error(); } } //Close PHP block. ?> Did this help? Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted July 4, 2007 Share Posted July 4, 2007 well seeing the other code would help but at the end of the day all you will be using is move_uploaded_file(). anything else is useful for validation and what ever other checks/mods you wish to perform but other wise that is it. make sure your form where you are uploading the file enctype="multipart/formdata" in the attributes. Quote Link to comment Share on other sites More sharing options...
dewey_witt Posted July 5, 2007 Author Share Posted July 5, 2007 OK im still not seeing how to intergrate the two. If anyone knows I'll.... I dunno I was gonna say kiss you on the mouth but ewwwww lol I realy realy realy realy need a fix to this. BADLY. Wanna do my sis? Ten bux? I have candy Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 great sample here http://w3schools.com/php/php_file_upload.asp Quote Link to comment Share on other sites More sharing options...
L Posted July 5, 2007 Share Posted July 5, 2007 haha, sweet teng84...i was just looking for something like that Quote Link to comment Share on other sites More sharing options...
dewey_witt Posted July 5, 2007 Author Share Posted July 5, 2007 Sweeeeeeeeeeeeet. Your awsome........ what do i owe you? A date with granny? JP For real I owe you one..... one last thing..... what do i have to modify to inert the file name into mysql database? ??? sql=" INSERT Pic Into somedb VALUES (.\"$file[name].\" ??????? Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 sql=" INSERT Pic Into somedb VALUES (".$file[name].")"; date? here in the philippines Quote Link to comment Share on other sites More sharing options...
dewey_witt Posted July 5, 2007 Author Share Posted July 5, 2007 Date = take a girl out for courtship. you wouldnt want my granny tho. she is OLD and prunned up! Thank you for all your wonderfull help! Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 5, 2007 Share Posted July 5, 2007 ??? Quote Link to comment 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.