
webmaster1
Members-
Posts
607 -
Joined
-
Last visited
Never
Everything posted by webmaster1
-
Okay, but its a little messy though functional nonetheless. <?php if (isset($_POST['submit'])) //PROCESS THE FORM WHEN THE SUBMIT BUTTON IS PRESSED { //VALIDATE THE INDIVIDUAL TEXT FIELDS AND DEFINE THEM AS TRUE OR FALSE BASED ON THE USER'S INPUT if (strlen($_POST['make']) > 0) {$make=TRUE;} else {$make=FALSE; $message_make=" *You forgot to enter the make!";} if (strlen($_POST['model']) > 0) {$model=TRUE;} else {$model=FALSE; $message_model=" *You forgot to enter the model!"; } if (strlen($_POST['price']) > 0) {$price=TRUE;} else {$price=FALSE; $message_price=" *You forgot to enter the price!";} if (strlen($_POST['engine']) > 0) {$engine=TRUE;} else {$engine=FALSE; $message_engine=" *You forgot to enter the engine!";} if (strlen($_POST['body']) > 0) {$body=TRUE;} else {$body=FALSE; $message_body=" *You forgot to enter the body!";} if (strlen($_POST['transmission']) > 0) {$transmission=TRUE;} else {$transmission=FALSE; $message_transmission=" *You forgot to enter the transmission!";} if (strlen($_POST['year']) > 0) {$year=TRUE;} else {$year=FALSE; $message_year=" *You forgot to enter the year!";} if (strlen($_POST['colour']) > 0) {$colour=TRUE;} else {$colour=FALSE; $message_colour=" *You forgot to enter the colour!";} if (strlen($_POST['mileagem']) > 0) {$mileagem=TRUE;} else {$mileagem=FALSE; $message_mileagem=" *You forgot to enter the mileage in miles!";} if (strlen($_POST['mileagekm']) > 0) {$mileagekm=TRUE;} else {$mileagekm=FALSE; $message_mileagekm=" *You forgot to enter the mileage in kilometres!";} if (strlen($_POST['owners']) > 0) {$owners=TRUE;} else {$owners=FALSE; $message_owners=" *You forgot to enter the owner!";} if (strlen($_POST['doors']) > 0) {$doors=TRUE;} else {$doors=FALSE; $message_doors=" *You forgot to enter the doors!";} if (strlen($_POST['location']) > 0) {$location=TRUE;} else {$location=FALSE; $message_location=" *You forgot to enter the location!";} if (isset($_POST['info'])) { $info = trim($_POST['info']); if ($info == "" || empty($info)) { $message_info = "Please enter data for info!"; } } $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0) { $filesize1=FALSE; $message_filesize1="You forgot to enter this image file!"; //echo "$message_filesize1"; } else { $filesize1=TRUE; } $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; if($filesize2==0) { $filesize2=FALSE; $message_filesize2="You forgot to enter this image file!"; //echo "$message_filesize2"; } else { $filesize2=TRUE; } $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize3==0) { $filesize3=FALSE; $message_filesize3="You forgot to enter this image file!"; //echo "$message_filesize3"; } else { $filesize3=TRUE; } //CHECK IF ANY THE FILES ARE THE SAME: $filenamecheck1= $HTTP_POST_FILES['ufile']['name'][0]; $filenamecheck2= $HTTP_POST_FILES['ufile']['name'][1]; $filenamecheck3= $HTTP_POST_FILES['ufile']['name'][2]; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if ( (($filenamecheck1 == $filenamecheck2) || ($filenamecheck2 == $filenamecheck3) || ($filenamecheck1 == $filenamecheck3)) && ((!$filesize1==0 && isset($_POST['submit'])) && (!$filesize2==0 && isset($_POST['submit'])) && (!$filesize3==0 && isset($_POST['submit']))) ) { $filenamecheck_message = "one ore more of the files are the same"; //echo "$message_filenamecheck"; $message_filenamecheck = TRUE; $filenamecheck1= FALSE; $filenamecheck2= FALSE; $filenamecheck3= FALSE; } else { $message_filenamecheck = FALSE; $filenamecheck1= TRUE; $filenamecheck2= TRUE; $filenamecheck3= TRUE; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //CHECK IF FILE 1 IS NOT *.JPEG OR *.GIF $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if ( ( ($HTTP_POST_FILES['ufile']["type"][0] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/pjpeg") ) // &&($HTTP_POST_FILES['ufile']["size"][0] < 50000) ) { $filetypecheck1=TRUE; } else { if (!($filesize1 == 0)) { $message_filetypecheck1=FALSE; $message_filetypecheck1="The first of the sumbitted files is not of a *.JPG ! *.GIF file type!"; echo "$message_filetypecheck1"; } } //CHECK IF FILE 2 IS NOT *.JPEG OR *.GIF $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; if ( ( ($HTTP_POST_FILES['ufile']["type"][1] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/pjpeg") ) // &&($HTTP_POST_FILES['ufile']["size"][1] < 50000) ) { $filetypecheck2=TRUE; } else { if (!($filesize2 == 0)) { $message_filetypecheck2=FALSE; $message_filetypecheck2="The second of the sumbitted files is not of a *.JPG ! *.GIF file type!"; echo "$message_filetypecheck2"; } } //CHECK IF FILE 3 IS NOT *.JPEG OR *.GIF $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if ( ( ($HTTP_POST_FILES['ufile']["type"][2] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/pjpeg") ) // &&($HTTP_POST_FILES['ufile']["size"][2] < 50000) ) { $filetypecheck3=TRUE; } else { if (!($filesize3 == 0)) { $message_filetypecheck3=FALSE; $message_filetypecheck3="The third of the sumbitted files is not of a *.JPG ! *.GIF file type!"; echo "$message_filetypecheck3"; } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //IF ALL INPUT FIELDS ARE DEFINED AS TRUE if //IF A: IF ALL FIELDS ARE DEFINED AS TRUE ($make && $model && $price && $engine && $body && $transmission && $year && $colour && $mileagem && $mileagekm && $owners && $doors && $location && $info && $filesize1 && $filesize2 && $filesize3 && $filenamecheck1 && filenamecheck2 && filenamecheck3 && $filetypecheck1 && $filetypecheck2 && $filetypecheck3) { //THEN A: DO THE FOLLOWING //THEN VALIDATE FILE UPLOADS //FIRST CHECK FILE TYPE BUT NOT SIZE ////////////////////// //B IF/THEN WAS 'ERE// ////////////////////// //DEFINE PATHS AS VARIABLES $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; //NEXT CHECK IF EITHER OF THE FILES ALREADY EXIST if //IF C: IF FILE EXISTS (file_exists($path1) || file_exists($path2) || file_exists($path3)) { //THEN C: RETURN ERROR echo "<b>ERROR</b></br></br> None of the selected image files have been uploaded as a result of either or both of the following incidents occurring:</br></br> 1) One or more of the image files you attempted to upload already exist on the server. Please ensure that you have not already uploaded the image file(s) and / or that each file name is unique.</br></br> Tip: Try naming the image files semantically after a combination of the make, model and year of the vehichle rather than a random series of letters and numbers. </br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } //CLOSE THEN C //NEXT POST THE IMAGES TO THE DESIGNATED FOLDER ON THE SERVER else { //ELSE C: UPLOAD IMAGES, SAVE PATH AND SUCCESS MESSAGE copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); //PICK UP AND DEFINE INPUT AS INDIVIDUAL VARIABLES $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $transmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; //DEFINE ADDITIONAL VARIABLES $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); //CONNECT TO RELEVANT DATABASE include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database."); //INSERT THE INPUT INTO DATABASE $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress','$path1','$path2','$path1')"; mysql_query($query); //NEXT DISPLAY A SUMMARY OF WHAT HAS BEEN UPLOADED echo "This item has been successfully submitted to the server.</br></br> The following image file have been appended to your uploaded:</br></br> "; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]." KB<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; //echo "<img src=\"$path1\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; //echo "<img src=\"$path2\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; //echo "<img src=\"$path3\" height=\"150\">"; echo "</br>It's best practice to confirm that your item has been submitted as desired</br></br> [place button here to link to view relevant section]</br></br> If you notice an error as a result of human input please find and delete the item indefinitely and reattempt its submission. Items should also be deleted as soon as they become redundant (e.g. vehichle sold)</br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } //CLOSE ELSE C //VERY IMPORTANT! EXIT(); WILL NO LONGER DISPLAY THE FORM exit(); } //CLOSE IF A (ALL FIELDS DEFINED AS TRUE) } // CLOSE OVERALL (IF SUBMIT) //END FORM PROCESS ?> <HTML> <HEAD> </HEAD> <BODY> <!--BEGIN FORM AND SET IT TO PROCESS SELF AND HANDLE MULTIPART/FORM-DATA--> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <fieldset> <?php // IF ANY INDIVIDUAL INPUT FIELD IS DEFINED AS FALSE THEN DISPLAY ERROR MESSAGE /* DO NOT INCLUDE || $filesize1 || $filesize2 || $filesize3 OTHERWISWE THE FORM WILL PRESENT THE BELOW ERROR MESSAGE TO THE USER THE BELOW CONDITIONS CHECK FOR ERROR MESSAGES DEFINED IN THE FORM PROCESS. THE ERROR MESSAGES FOR FILE UPLOAD INPUT ELEMENTS ARE NOT DEFINED IN THE FORM PROCESS */ if ($message_make || $message_model || $message_price || $message_engine || $message_body || $message_transmission || $message_year || $message_colour || $message_mileagem || $message_mileagekm || $message_owners || $message_doors || $message_location || $message_info || $message_filesize2 || $message_filesize1 || $message_filesize2 || $message_filesize3 || $message_filesize1 || $message_filesize2 || $message_filesize3 || $message_filenamecheck || $message_filetypecheck1 || $message_filetypecheck2 || $message_filetypecheck3) // echo '*Your request could not be sent because some of the information is missing.</br></br>'; ?> <ol> <!--BEGIN REGULAR TEXT FIELDS--> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text" value="<?php if (isset($_POST['make'])) echo $_POST['make']; ?>"/> <?php if ($message_make) echo ''.$message_make.''; ?></br> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>"/> <?php if ($message_model) echo ''.$message_model.''; ?></br> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>"/> <?php if ($message_price) echo ''.$message_price.''; ?></br> </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text" value="<?php if (isset($_POST['engine'])) echo $_POST['engine']; ?>"/> <?php if ($message_engine) echo ''.$message_engine.''; ?></br> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text" value="<?php if (isset($_POST['body'])) echo $_POST['body']; ?>"/> <?php if ($message_body) echo ''.$message_body.''; ?></br> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text" value="<?php if (isset($_POST['transmission'])) echo $_POST['transmission']; ?>"/> <?php if ($message_transmission) echo ''.$message_transmission.''; ?></br> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text" value="<?php if (isset($_POST['year'])) echo $_POST['year']; ?>"/> <?php if ($message_year) echo ''.$message_year.''; ?></br> </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text" value="<?php if (isset($_POST['colour'])) echo $_POST['colour']; ?>"/> <?php if ($message_colour) echo ''.$message_colour.''; ?></br> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text" value="<?php if (isset($_POST['mileagem'])) echo $_POST['mileagem']; ?>"/> <?php if ($message_mileagem) echo ''.$message_mileagem.''; ?></br> </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text" value="<?php if (isset($_POST['mileagekm'])) echo $_POST['mileagekm']; ?>"/> <?php if ($message_mileagekm) echo ''.$message_mileagekm.''; ?></br> </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text" value="<?php if (isset($_POST['owners'])) echo $_POST['owners']; ?>"/> <?php if ($message_owners) echo ''.$message_owners.''; ?></br> </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text" value="<?php if (isset($_POST['doors'])) echo $_POST['doors']; ?>"/> <?php if ($message_doors) echo ''.$message_doors.''; ?></br> </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text" value="<?php if (isset($_POST['location'])) echo $_POST['location']; ?>"/> <?php if ($message_location) echo ''.$message_location.''; ?></br> </li> <!--BEGIN TEXT AREA--> <li> <label for="info">Additional Information:</label></br> <textarea name="info" rows="5" cols="50"/> <?php if (isset($_POST['info'])) echo stripslashes($_POST['info']); ?> </textarea> <?php if ($message_info) echo ''.$message_info.''; ?></br> </li> <!--BEGIN FILE UPLOADS--> <li> <label for "ufile[]">Image File 1:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php //AN ALTERNATIVE WAY CAN BE FOUND HERE: http://www.phpfreaks.com/forums/index.php/topic,226156.0.html $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0 && isset($_POST['submit'])) { $filesize1=FALSE; $message_filesize1="You forgot to enter this image file!"; echo "$message_filesize1"; } else { $filesize1=TRUE; } ?> </li> <li> <label for "ufile[]">Image File 2:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; if($filesize2==0 && isset($_POST['submit'])) { $filesize2=FALSE; $message_filesize2="You forgot to enter this image file!"; echo "$message_filesize2"; } else { $filesize2=TRUE; } ?> </li> <li> <label for "ufile[]">Image File 3:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize3==0 && isset($_POST['submit'])) { $filesize3=FALSE; $message_filesize3="You forgot to enter this image file!"; echo "$message_filesize3"; } else { $filesize3=TRUE; } ?> <?php //CHECK IF ANY THE FILES ARE THE SAME: $filenamecheck1= $HTTP_POST_FILES['ufile']['name'][0]; $filenamecheck2= $HTTP_POST_FILES['ufile']['name'][1]; $filenamecheck3= $HTTP_POST_FILES['ufile']['name'][2]; $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if ( (($filenamecheck1 == $filenamecheck2) || ($filenamecheck2 == $filenamecheck3) || ($filenamecheck1 == $filenamecheck3)) && ((!$filesize1==0 && isset($_POST['submit'])) && (!$filesize2==0 && isset($_POST['submit'])) && (!$filesize3==0 && isset($_POST['submit']))) ) { $filenamecheck_message = "one ore more of the files are the same"; echo "$filenamecheck_message"; $filenamecheck_message = TRUE; //$filenamecheck1= FALSE; //$filenamecheck2= FALSE; //$filenamecheck3= FALSE; } else { $filenamecheck_message = FALSE; //$filenamecheck1= TRUE; //$filenamecheck2= TRUE; //$filenamecheck3= TRUE; } ?> </li> <li> <input name="submit" type="submit"> </li> </ol> </fieldset> </form> </BODY> </HTML> Anytime an error message is given the upload fields reset.
-
Hi All, I have a form that displays errors beneath each requisite field (e.g. not numeric, empty, invalid file type) when validated. When the form process results in an error the values remain in my text fields but the upload fields reset (blank). Is there away of retaining the user input in upload fields that are valid even after the form processes itself? (Is this what 'sticky' means?)
-
[SOLVED] Positioning Basic Error Message (driving me insane!)
webmaster1 replied to webmaster1's topic in PHP Coding Help
That worked blueman378. Much thanks. I also tried this and it worked: <?php $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0 && isset($_POST['submit'])) { $message_filesize1="You forgot to enter this image file!"; echo "$message_filesize1"; } ?> You'll notice I just added && isset($_POST['submit']) to the if part of the statement. Is this way correct too? -
[SOLVED] Positioning Basic Error Message (driving me insane!)
webmaster1 replied to webmaster1's topic in PHP Coding Help
I wouldn't think so. The zero means 'the file size is zero' and not 'array number zero'. -
[SOLVED] Positioning Basic Error Message (driving me insane!)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Nope, but just did. Isn't this just checking whether or not the files were loaded? I need to check whether or not the field is empty BEFORE the form begins the upload. Here's my full code if it helps: <?php if (isset($_POST['submit'])) //PROCESS THE FORM WHEN THE SUBMIT BUTTON IS PRESSED { //VALIDATE THE INDIVIDUAL TEXT FIELDS AND DEFINE THEM AS TRUE OR FALSE BASED ON THE USER'S INPUT if (strlen($_POST['make']) > 0) {$make=TRUE;} else {$make=FALSE; $message_make=" *You forgot to enter the make!";} if (strlen($_POST['model']) > 0) {$model=TRUE;} else {$model=FALSE; $message_model=" *You forgot to enter the model!"; } if (strlen($_POST['price']) > 0) {$price=TRUE;} else {$price=FALSE; $message_price=" *You forgot to enter the price!";} if (strlen($_POST['engine']) > 0) {$engine=TRUE;} else {$engine=FALSE; $message_engine=" *You forgot to enter the engine!";} if (strlen($_POST['body']) > 0) {$body=TRUE;} else {$body=FALSE; $message_body=" *You forgot to enter the body!";} if (strlen($_POST['transmission']) > 0) {$transmission=TRUE;} else {$transmission=FALSE; $message_transmission=" *You forgot to enter the transmission!";} if (strlen($_POST['year']) > 0) {$year=TRUE;} else {$year=FALSE; $message_year=" *You forgot to enter the year!";} if (strlen($_POST['colour']) > 0) {$colour=TRUE;} else {$colour=FALSE; $message_colour=" *You forgot to enter the colour!";} if (strlen($_POST['mileagem']) > 0) {$mileagem=TRUE;} else {$mileagem=FALSE; $message_mileagem=" *You forgot to enter the mileage in miles!";} if (strlen($_POST['mileagekm']) > 0) {$mileagekm=TRUE;} else {$mileagekm=FALSE; $message_mileagekm=" *You forgot to enter the mileage in kilometres!";} if (strlen($_POST['owners']) > 0) {$owners=TRUE;} else {$owners=FALSE; $message_owners=" *You forgot to enter the owner!";} if (strlen($_POST['doors']) > 0) {$doors=TRUE;} else {$doors=FALSE; $message_doors=" *You forgot to enter the doors!";} if (strlen($_POST['location']) > 0) {$location=TRUE;} else {$location=FALSE; $message_location=" *You forgot to enter the location!";} if (isset($_POST['info'])) { $info = trim($_POST['info']); if ($info == "" || empty($info)) { $message_info = "Please enter data for info!"; } } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0) { $filesize1=FALSE; //$message_filesize1="You forgot to enter this image file!"; //echo "$message_filesize1"; } else { $filesize1=TRUE; } $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; if($filesize2==0) { $filesize2=FALSE; //$message_filesize2="You forgot to enter this image file!"; //echo "$message_filesize2"; } else { $filesize2=TRUE; } $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize3==0) { $filesize3=FALSE; //$message_filesize3="You forgot to enter this image file!"; //echo "$message_filesize3"; } else { $filesize3=TRUE; } /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //IF ALL INPUT FIELDS ARE DEFINED AS TRUE if ($make && $model && $price && $engine && $body && $transmission && $year && $colour && $mileagem && $mileagekm && $owners && $doors && $location && $info && $filesize1 && $filesize2 && $filesize3) { //THEN VALIDATE FILE UPLOADS //FIRST CHECK FILE TYPE BUT NOT SIZE if ( ( //BEGIN IMAGE FILE 1 ( ($HTTP_POST_FILES['ufile']["type"][0] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][0] < 50000) //END IMAGE FILE 1 ) && ( //BEGIN IMAGE FILE 2 ( ($HTTP_POST_FILES['ufile']["type"][1] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][1] < 50000) //END IMAGE FILE 2 ) && ( //BEGIN IMAGE FILE 3 ( ($HTTP_POST_FILES['ufile']["type"][2] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][2] < 50000) //END IMAGE FILE 3 ) ) { //DEFINE PATHS AS VARIABLES $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; //NEXT CHECK IF EITHER OF THE FILES ALREADY EXIST if (file_exists($path1) || file_exists($path2) || file_exists($path3)) { echo "<b>ERROR</b></br></br> None of the selected image files have been uploaded as a result of either or both of the following incidents occurring:</br></br> 1) One or more of the image files you attempted to upload already exist on the server. Please ensure that you have not already uploaded the image file(s) and / or that each file name is unique.</br></br> Tip: Try naming the image files semantically after a combination of the make, model and year of the vehichle rather than a random series of letters and numbers. </br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } //NEXT POST THE IMAGES TO THE DESIGNATED FOLDER ON THE SERVER else { copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); //PICK UP AND DEFINE INPUT AS INDIVIDUAL VARIABLES $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $transmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; //DEFINE ADDITIONAL VARIABLES $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); //CONNECT TO RELEVANT DATABASE include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database."); //INSERT THE INPUT INTO DATABASE $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress','$path1','$path2','$path1')"; mysql_query($query); //NEXT DISPLAY A SUMMARY OF WHAT HAS BEEN UPLOADED echo "This item has been successfully submitted to the server.</br></br> The following image file have been appended to your uploaded:</br></br> "; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]." KB<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; //echo "<img src=\"$path1\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; //echo "<img src=\"$path2\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; //echo "<img src=\"$path3\" height=\"150\">"; echo "</br>It's best practice to confirm that your item has been submitted as desired</br></br> [place button here to link to view relevant section]</br></br> If you notice an error as a result of human input please find and delete the item indefinitely and reattempt its submission. Items should also be deleted as soon as they become redundant (e.g. vehichle sold)</br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } } else { echo "<b>Error</b></br></br> None of the selected image files have been uploaded as a result of either or both of the following incidents occurring:</br></br> 1) One or more of the submitted file types is not *.gif, *.jpeg or *.pjpeg.</br></br> Click the back button on your browser to continue. "; } //VERY IMPORTANT! EXIT(); WILL NO LONGER DISPLAY THE FORM exit(); } } //END FORM PROCESS ?> <HTML> <HEAD> </HEAD> <BODY> <!--BEGIN FORM AND SET IT TO PROCESS SELF AND HANDLE MULTIPART/FORM-DATA--> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <fieldset> <?php // IF ANY INDIVIDUAL INPUT FIELD IS DEFINED AS FALSE THEN DISPLAY ERROR MESSAGE /* DO NOT INCLUDE || $filesize1 || $filesize2 || $filesize3 OTHERWISWE THE FORM WILL PRESENT THE BELOW ERROR MESSAGE TO THE USER THE BELOW CONDITIONS CHECK FOR ERROR MESSAGES DEFINED IN THE FORM PROCESS. THE ERROR MESSAGES FOR FILE UPLOAD INPUT ELEMENTS ARE NOT DEFINED IN THE FORM PROCESS */ if ($message_make || $message_model || $message_price || $message_engine || $message_body || $message_transmission || $message_year || $message_colour || $message_mileagem || $message_mileagekm || $message_owners || $message_doors || $message_location || $message_info) echo '*Your request could not be sent because some of the information is missing.</br></br>'; ?> <ol> <!--BEGIN REGULAR TEXT FIELDS--> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text" value="<?php if (isset($_POST['make'])) echo $_POST['make']; ?>"/> <?php if ($message_make) echo ''.$message_make.''; ?></br> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>"/> <?php if ($message_model) echo ''.$message_model.''; ?></br> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>"/> <?php if ($message_price) echo ''.$message_price.''; ?></br> </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text" value="<?php if (isset($_POST['engine'])) echo $_POST['engine']; ?>"/> <?php if ($message_engine) echo ''.$message_engine.''; ?></br> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text" value="<?php if (isset($_POST['body'])) echo $_POST['body']; ?>"/> <?php if ($message_body) echo ''.$message_body.''; ?></br> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text" value="<?php if (isset($_POST['transmission'])) echo $_POST['transmission']; ?>"/> <?php if ($message_transmission) echo ''.$message_transmission.''; ?></br> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text" value="<?php if (isset($_POST['year'])) echo $_POST['year']; ?>"/> <?php if ($message_year) echo ''.$message_year.''; ?></br> </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text" value="<?php if (isset($_POST['colour'])) echo $_POST['colour']; ?>"/> <?php if ($message_colour) echo ''.$message_colour.''; ?></br> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text" value="<?php if (isset($_POST['mileagem'])) echo $_POST['mileagem']; ?>"/> <?php if ($message_mileagem) echo ''.$message_mileagem.''; ?></br> </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text" value="<?php if (isset($_POST['mileagekm'])) echo $_POST['mileagekm']; ?>"/> <?php if ($message_mileagekm) echo ''.$message_mileagekm.''; ?></br> </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text" value="<?php if (isset($_POST['owners'])) echo $_POST['owners']; ?>"/> <?php if ($message_owners) echo ''.$message_owners.''; ?></br> </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text" value="<?php if (isset($_POST['doors'])) echo $_POST['doors']; ?>"/> <?php if ($message_doors) echo ''.$message_doors.''; ?></br> </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text" value="<?php if (isset($_POST['location'])) echo $_POST['location']; ?>"/> <?php if ($message_location) echo ''.$message_location.''; ?></br> </li> <!--BEGIN TEXT AREA--> <li> <label for="info">Additional Information:</label></br> <textarea name="info" rows="5" cols="50"/> <?php if (isset($_POST['info'])) echo stripslashes($_POST['info']); ?> </textarea> <?php if ($message_info) echo ''.$message_info.''; ?></br> </li> <!--BEGIN FILE UPLOADS--> <li> <label for "ufile[]">Image File 1:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0) { $filesize1=FALSE; $message_filesize1="You forgot to enter this image file!"; echo "$message_filesize1"; } else { $filesize1=TRUE; } ?> </li> <li> <label for "ufile[]">Image File 2:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php $filesize2=$HTTP_POST_FILES['ufile']['size'][1]; if($filesize2==0) { $filesize2=FALSE; $message_filesize2="You forgot to enter this image file!"; echo "$message_filesize2"; } else { $filesize2=TRUE; } ?> </li> <li> <label for "ufile[]">Image File 3:</label> <input type="file" name="ufile[]" id="ufile[]"/> <!--NOTICE THAT THIS ERROR DOES NOT CALL ON A VARIABLE IN THE FORM PROCESS LIKE THE TEXT FIELDS.--> <?php $filesize3=$HTTP_POST_FILES['ufile']['size'][2]; if($filesize3==0) { $filesize3=FALSE; $message_filesize3="You forgot to enter this image file!"; echo "$message_filesize3"; } else { $filesize3=TRUE; } ?> </li> <li> <input name="submit" type="submit"> </li> </ol> </fieldset> </form> </BODY> </HTML> -
Hi All, I'm trying to display an error message beneath an input field in my form. This happens in the form process: <?php $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0) { $filesize1=FALSE; //I'VE COMMENTED THIS OUT BECAUSE I DON'T WANT THE MESSAGE AT THE TOP OF MY PAGE //$message_filesize1="You forgot to enter this image file!"; //echo "$message_filesize1"; } else { $filesize1=TRUE; } ?> This is how I want the error message to work: <input type="file" name="ufile[]" id="ufile[]"/> <?php $filesize1=$HTTP_POST_FILES['ufile']['size'][0]; if($filesize1==0) { $filesize1=FALSE; $message_filesize1="You forgot to enter this image file!"; echo "$message_filesize1"; } else { $filesize1=TRUE; } ?> Intead the error message already shows on the form before any input or hitting of the submit button. I have tried so many different angles but I can't get this to work. Please help a meagre newb. ???
-
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
That worked great. Thanks Premiso. Any takers on the validating the file upload: <li> <label for "ufile[]">Image File 1:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 2:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 3:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> I just need to check if the fields are empty. (If you're feeling extra generous I need to check if any of them equal each other ) -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Oops! Here's the text area: <textarea name="info" rows="5" cols="50"/> <?php if (isset($_POST['info'])) echo stripslashes($_POST['info']); ?> </textarea> -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Yay! I've done it! Well almost... There's only two things left. Firstly how do I validate if (strlen($_POST['xxx']) > 0) for an array of three upload files (this is fixed so there won't be more or less than 3). I've tried if (strlen($_POST['ufile[]']) > 0) but I get an error. PFMaBiSmAd's code looks great but I already validate the actual images when processing the form. All I need is a snippet of code to validate that the fields are not empty. Secondly I'm not sure how to validate if a text area is empty since its html syntax is different from a reguler text input field Here's the full code (please review it before answering - thanks) <?php if (isset($_POST['submit'])) //PROCESS THE FORM WHEN THE SUBMIT BUTTON IS PRESSED { //VALIDATE THE INDIVIDUAL TEXT FIELDS AND DEFINE THEM AS TRUE OR FALSE BASED ON THE USER'S INPUT if (strlen($_POST['make']) > 0) {$make=TRUE;} else {$make=FALSE; $message_make=" *You forgot to enter the make!";} if (strlen($_POST['model']) > 0) {$model=TRUE;} else {$model=FALSE; $message_model=" *You forgot to enter the model!"; } if (strlen($_POST['price']) > 0) {$price=TRUE;} else {$price=FALSE; $message_price=" *You forgot to enter the price!";} if (strlen($_POST['engine']) > 0) {$engine=TRUE;} else {$engine=FALSE; $message_engine=" *You forgot to enter the engine!";} if (strlen($_POST['body']) > 0) {$body=TRUE;} else {$body=FALSE; $message_body=" *You forgot to enter the body!";} if (strlen($_POST['transmission']) > 0) {$transmission=TRUE;} else {$transmission=FALSE; $message_transmission=" *You forgot to enter the transmission!";} if (strlen($_POST['year']) > 0) {$year=TRUE;} else {$year=FALSE; $message_year=" *You forgot to enter the year!";} if (strlen($_POST['colour']) > 0) {$colour=TRUE;} else {$colour=FALSE; $message_colour=" *You forgot to enter the colour!";} if (strlen($_POST['mileagem']) > 0) {$mileagem=TRUE;} else {$mileagem=FALSE; $message_mileagem=" *You forgot to enter the mileage in miles!";} if (strlen($_POST['mileagekm']) > 0) {$mileagekm=TRUE;} else {$mileagekm=FALSE; $message_mileagekm=" *You forgot to enter the mileage in kilometres!";} if (strlen($_POST['owners']) > 0) {$owners=TRUE;} else {$owners=FALSE; $message_owners=" *You forgot to enter the owner!";} if (strlen($_POST['doors']) > 0) {$doors=TRUE;} else {$doors=FALSE; $message_doors=" *You forgot to enter the doors!";} if (strlen($_POST['location']) > 0) {$location=TRUE;} else {$location=FALSE; $message_location=" *You forgot to enter the location!";} //IF ALL INPUT FIELDS ARE DEFINED AS TRUE if ($make && $model && $price && $engine && $body && $transmission && $year && $colour && $mileagem && $mileagekm && $owners && $doors && $location) { //THEN VALIDATE FILE UPLOADS //FIRST CHECK FILE TYPE BUT NOT SIZE if ( ( //BEGIN IMAGE FILE 1 ( ($HTTP_POST_FILES['ufile']["type"][0] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][0] < 50000) //END IMAGE FILE 1 ) && ( //BEGIN IMAGE FILE 2 ( ($HTTP_POST_FILES['ufile']["type"][1] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][1] < 50000) //END IMAGE FILE 2 ) && ( //BEGIN IMAGE FILE 3 ( ($HTTP_POST_FILES['ufile']["type"][2] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][2] < 50000) //END IMAGE FILE 3 ) ) { //DEFINE PATHS AS VARIABLES $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; //NEXT CHECK IF EITHER OF THE FILES ALREADY EXIST if (file_exists($path1) || file_exists($path2) || file_exists($path3)) { echo "<b>ERROR</b></br></br> 1 One or more of the image files you attempted to upload already exist on the server. Please ensure that you have not already uploaded the image file(s) and / or that each file name is unique.</br></br> Tip: Try naming the image files semantically after a combination of the make, model and year of the vehichle rather than a random series of letters and numbers. </br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } //NEXT POST THE IMAGES TO THE DESIGNATED FOLDER ON THE SERVER else { copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); //PICK UP AND DEFINE INPUT AS INDIVIDUAL VARIABLES $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $transmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; //DEFINE ADDITIONAL VARIABLES $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); //CONNECT TO RELEVANT DATABASE include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to the relevant database."); //INSERT THE INPUT INTO DATABASE $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress','$path1','$path2','$path1')"; mysql_query($query); //NEXT DISPLAY A SUMMARY OF WHAT HAS BEEN UPLOADED echo "This item has been successfully submitted to the server.</br></br> The following image file have been appended to your uploaded:</br></br> "; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]." KB<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; //echo "<img src=\"$path1\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; //echo "<img src=\"$path2\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; //echo "<img src=\"$path3\" height=\"150\">"; echo "</br>It's best practice to confirm that your item has been submitted as desired</br></br> [place button here to link to view relevant section]</br></br> If you notice an error as a result of human input please find and delete the item indefinitely and reattempt its submission. Itens should also be deleted as soon as they become redundant (e.g. vehichle sold)</br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } } else { echo "<b>Error</b></br></br> 1) One or more of the submitted file types is not *.gif, *.jpeg or *.pjpeg.</br></br> Click the back button on your browser to continue. "; } //VERY IMPORTANT! EXIT(); WILL NO LONGER DISPLAY THE FORM exit(); } } //END FORM PROCESS ?> <HTML> <HEAD> </HEAD> <BODY> <!--BEGIN FORM AND SET IT TO PROCESS SELF AND HANDLE MULTIPART/FORM-DATA--> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data"> <fieldset> <?php // IF ANY INDIVIDUAL INPUT FIELD IS DEFINED AS FALSE THEN DISPLAY ERROR MESSAGE if ($message_make || $message_model || $message_price || $message_engine || $message_body || $message_transmission || $message_year || $message_colour || $message_mileagem || $message_mileagekm || $message_owners || $message_doors || $message_location) echo '*Your request could not be sent because some of the information is missing.</br></br>'; ?> <ol> <!--BEGIN REGULAR TEXT FIELDS--> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text" value="<?php if (isset($_POST['make'])) echo $_POST['make']; ?>"/> <?php if ($message_make) echo ''.$message_make.''; ?></br> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text" value="<?php if (isset($_POST['model'])) echo $_POST['model']; ?>"/> <?php if ($message_model) echo ''.$message_model.''; ?></br> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text" value="<?php if (isset($_POST['price'])) echo $_POST['price']; ?>"/> <?php if ($message_price) echo ''.$message_price.''; ?></br> </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text" value="<?php if (isset($_POST['engine'])) echo $_POST['engine']; ?>"/> <?php if ($message_engine) echo ''.$message_engine.''; ?></br> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text" value="<?php if (isset($_POST['body'])) echo $_POST['body']; ?>"/> <?php if ($message_body) echo ''.$message_body.''; ?></br> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text" value="<?php if (isset($_POST['transmission'])) echo $_POST['transmission']; ?>"/> <?php if ($message_transmission) echo ''.$message_transmission.''; ?></br> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text" value="<?php if (isset($_POST['year'])) echo $_POST['year']; ?>"/> <?php if ($message_year) echo ''.$message_year.''; ?></br> </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text" value="<?php if (isset($_POST['colour'])) echo $_POST['colour']; ?>"/> <?php if ($message_colour) echo ''.$message_colour.''; ?></br> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text" value="<?php if (isset($_POST['mileagem'])) echo $_POST['mileagem']; ?>"/> <?php if ($message_mileagem) echo ''.$message_mileagem.''; ?></br> </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text" value="<?php if (isset($_POST['mileagekm'])) echo $_POST['mileagekm']; ?>"/> <?php if ($message_mileagekm) echo ''.$message_mileagekm.''; ?></br> </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text" value="<?php if (isset($_POST['owners'])) echo $_POST['owners']; ?>"/> <?php if ($message_owners) echo ''.$message_owners.''; ?></br> </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text" value="<?php if (isset($_POST['doors'])) echo $_POST['doors']; ?>"/> <?php if ($message_doors) echo ''.$message_doors.''; ?></br> </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text" value="<?php if (isset($_POST['location'])) echo $_POST['location']; ?>"/> <?php if ($message_location) echo ''.$message_location.''; ?></br> </li> <!--BEGIN TEXT AREA--> <!--BEGIN FILE UPLOADS--> <li> <label for "ufile[]">Image File 1:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 2:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 3:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <input name="submit" type="submit"> </li> </ol> </fieldset> </form> </BODY> </HTML> -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Thanks, I'll start breaking this appart now. The provided link only handles regular text input validation which I still can't get a handle on. Most tutorials show me blocks of code but hardly none at all show me how it all stiches together. (e.g. in your code I don't know what triggers the cases and how it should slot it with my code) -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Sorry to flog a dead horse but can anybody help me with this? I'm having so much difficulty trying to validate and process my form in the same page. -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
FYI I've been trying to stitch together the validation piece by piece but none of my error messages are being called on. I tried this way as well but to avail: http://www.lotsofcode.com/php/validation.htm Help me PHP Kenobi; you're my only hope. -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Also I seem to be stuck on how or where to check if ... $HTTP_POST_FILES['ufile']['name'][0] $HTTP_POST_FILES['ufile']['name'][1] $HTTP_POST_FILES['ufile']['name'][2] ... equal the same image (i.e. the user uploaded the same image more than once in the one submit) -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
Hi PFMaBiSmAd , You're going to kill me but changed my code when you were in midpost. What you saw was the first rendition. Could you shine some light on code as its posted now? So sorry -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
So after the if (empty($errors)) I can just paste in all the code I thought I had to have in a seperate page? Here's my code to process the form by the way. I know its probably messy but I'm very proud of it (newbishly of course). <?php //FIRST CHECK FILE TYPE BUT NOT SIZE if ( ( //BEGIN IMAGE FILE 1 ( ($HTTP_POST_FILES['ufile']["type"][0] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][0] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][0] < 50000) //END IMAGE FILE 1 ) && ( //BEGIN IMAGE FILE 2 ( ($HTTP_POST_FILES['ufile']["type"][1] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][1] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][1] < 50000) //END IMAGE FILE 2 ) && ( //BEGIN IMAGE FILE 3 ( ($HTTP_POST_FILES['ufile']["type"][2] == "image/gif") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/jpeg") || ($HTTP_POST_FILES['ufile']["type"][2] == "image/pjpeg") ) //&&($HTTP_POST_FILES['ufile']["size"][2] < 50000) //END IMAGE FILE 3 ) ) { //DEFINE PATHS AS VARIABLES $path1= "upload/".$HTTP_POST_FILES['ufile']['name'][0]; $path2= "upload/".$HTTP_POST_FILES['ufile']['name'][1]; $path3= "upload/".$HTTP_POST_FILES['ufile']['name'][2]; //NEXT CHECK IF EITHER OF THE FILES ALREADY EXIST if (file_exists($path1) || file_exists($path2) || file_exists($path3)) { echo "<b>ERROR</b></br></br> None of the selected image files have been uploaded as a result of either or both of the following incidents occurring:</br></br> 1) The requisite amount of files have not been uploaded (three images minimum / maximum).</br> 2) One or more of the image files you attempted to upload already exist on the server. Please ensure that you have not already uploaded the image file(s) and / or that each file name is unique.</br></br> Tip: Try naming the image files semantically after a combination of the make, model and year of the vehichle rather than a random series of letters and numbers. </br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } //NEXT POST THE IMAGES TO THE DESIGNATED FOLDER ON THE SERVER else { copy($HTTP_POST_FILES['ufile']['tmp_name'][0], $path1); copy($HTTP_POST_FILES['ufile']['tmp_name'][1], $path2); copy($HTTP_POST_FILES['ufile']['tmp_name'][2], $path3); //PICK UP THE VARIABLES FROM THE TEXT FIELDS //$imgurl1 = "upload/" . $_FILES["file"]["name"]; $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $transmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; $info = $_POST['info']; //DEFINE ADDITIONAL VARIABLES $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); //NOW CONNECT TO DATABASE include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to database."); // INSERT INTO DATABASE // Insert into database $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress','$path1','$path2','$path3')"; mysql_query($query); //NEXT DISPLAY A SUMMARY OF WHAT HAS BEEN UPLOADED echo "This item has been successfully submitted to the server.</br></br> The following image file have been appended to your uploaded:</br></br> "; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][0]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][0]." KB<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][0]."<BR/>"; //echo "<img src=\"$path1\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][1]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][1]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][1]."<BR/>"; //echo "<img src=\"$path2\" height=\"150\">"; echo "<P>"; echo "File Name :".$HTTP_POST_FILES['ufile']['name'][2]."<BR/>"; //echo "File Size :".$HTTP_POST_FILES['ufile']['size'][2]."<BR/>"; echo "File Type :".$HTTP_POST_FILES['ufile']['type'][2]."<BR/>"; //echo "<img src=\"$path3\" height=\"150\">"; echo "</br>It's best practice to confirm that your item has been submitted as desired</br></br> [place button here to link to view relevant section]</br></br> If you notice an error as a result of human input please find and delete the item indefinitely and reattempt its submission. Itens should also be deleted as soon as they become redundant (e.g. vehichle sold)</br></br> Should you experience further technical difficulty please contact the web master:</br></br> [place button here to link to web master cms error log form] "; } } else { echo "<b>Error</b></br></br> None of the selected image files have been uploaded as a result of either or both of the following incidents occurring:</br></br> 1) One or more of the submitted file types is not *.gif, *.jpeg or *.pjpeg.</br></br> 2) All three file upload fields were left blank. (can this be prevented with validation?)</br></br> Click the back button on your browser to continue. "; } ?> Here's the form itself: <html> <head> <link rel="stylesheet" href="productpage.css" type="text/css" /> </head> <body> <strong>Please ensure that the image files have already been conventionally optimized for the web browsing.[link to learn how] </br></br>While image files of any size can be uploaded it is strongly advised against. </br></br>Excessivley large image files will significantly take longer to upload to the server, impede unnecessary server space and hinder the load time of particular sections of the site.</br></br> <form action="inputdata4.php" method="post" enctype="multipart/form-data"> <fieldset> <ol> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text"> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text"> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text"> </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text"> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text"> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text"> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text"> </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text"> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text"> </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text"> </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text"> </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text"> </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text"> </li> <li> <label for="info">Additional Info:</label> <textarea name="info" id="info"></textarea> </li> <li> <label for "ufile[]">Image File 1:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 2:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <label for "ufile[]">Image File 3:</label> <input type="file" name="ufile[]" id="ufile[]"/> </li> <li> <input type="submit" name="Submit" value="Submit" onclick = "this.style.visibility = 'hidden'; loading.style.visibility = 'visible';"/> </li> </ol> </fieldset> </form> </body> </html> Its all functioning btw -
Quick Question: Form Validation (Newbish)
webmaster1 replied to webmaster1's topic in PHP Coding Help
That exactly what I was looking to do. Its great the way the error messages pop up in a relevant spot too. Just two more questions on the below lines of code: if ($_POST) Does this mean 'when the submit button is clicked and the form is posting'? if (empty($errors)) What exactly would I do here? I'm not sure I understand what the action is. Do I need to add additional code here to make my form post or would I just put a message in like "No errors were found"? -
Hi Freaks! I've just finished building a form consisting of text and file input fields. I have a second file that the form is posted to that sends the input to a mySQL database. I've fished around Google but I don't know whether to use CLIENT SIDE (javascript) or SERVER SIDE (php). What I do know is that I want the validation to occur on the form page BEFORE THE FORM ACTUALLY POSTS and I don't want to use alert boxes either. Can anybody show me a quick example of the mechanics of form validation error messages based on the below form and included comments: <?php //check that just this field isn't empty <input name="ufile[]" type="file" id="ufile[]" size="50" /></br> //check that none of the next three fields are empty <input name="ufile[]" type="file" id="ufile[]" size="50" /></br> <input name="ufile[]" type="file" id="ufile[]" size="50" /></br> <input name="ufile[]" type="file" id="ufile[]" size="50" /></br> //check that value is numeric and contains only four digits but no comma or euro symbol <input type="text" name="number" id="number" class="text"></br> //check that value contains letters only <input type="text" name="letter" id="letter" class="text"></br> ?> I'm not sure when or how to use striplashes, empty or isset. The above form is just an example based on what I need to know. A useful link might also suffice.
-
Loading images to mySQL using a PHP form?
webmaster1 replied to webmaster1's topic in PHP Coding Help
I've now combined my original form with the image file upload feature. inputform.php <html> <head> <link rel="stylesheet" href="productpage.css" type="text/css" /> </head> <body> <form action="inputdata.php" method="post" enctype="multipart/form-data"> <fieldset> <ol> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text"> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text"> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text"> </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text"> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text"> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text"> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text"> </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text"> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text"> </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text"> </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text"> </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text"> </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text"> </li> <li> <label for="info">Additional Info:</label> <textarea name="info" id="info"></textarea> </li> <li> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> </li> <li> <input type="submit" name="submit" value="Submit" /> </li> </ol> </fieldset> </form> </body> </html> inputdata.php <?php // CONDITION A IF: file type is jpg or gif and less than 20000/1024 if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 20000)) // CONDITION A THEN: { // CONDITION B IF: errors are greater than 1 if ($_FILES["file"]["error"] > 0) // CONDITION B THEN: an error return code is given { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } // CONDITION B OTHERWISE: upload the file to the folder else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; // CONDITION C IF: file exists if (file_exists("upload/" . $_FILES["file"]["name"])) // CONDITION C THEN: return an error message to the user { echo $_FILES["file"]["name"] . " <b>already exists and HAS NOT BEEN UPLOADED! Please ensure that you have not already uploaded this file and/or its file name is unique.<b> "; } // CONDITION C OTHERWISE: upload the image and return a message that the file has been loaded successfully else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; // AND INSERT URL INTO DATABASE // define variables $imgurl = "upload/" . $_FILES["file"]["name"]; $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $transmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; $info = $_POST['info']; // Additional variables not posted from form $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); // Connect to database include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to database."); // Insert into database //$query = "INSERT INTO test VALUES ('','$make','','','','','','','','','','','','','','','','$imgurl')"; //mysql_query($query); // Insert into database $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress','$imgurl')"; mysql_query($query); } // CONDITION B OTHERWISE CLOSE BRACKET BELOW } // CONDITION A THEN CLOSE BRACKET BELOW } else { echo "Invalid file. Please submit a .jpg or .gif file only"; } ?> As ye can see I placed comments in the above script as recommended by cunoodle2. Next step: Figure out how to integrate two additional and simutaneous file uploads. ??? -
Loading images to mySQL using a PHP form?
webmaster1 replied to webmaster1's topic in PHP Coding Help
I've made some progress. So far I can get the image to write to a folder. I'll attempt to integrate it into my original form shortly. I'm going to post this for any fellow newbs that come across this thread via search engine. I know all of this may seem blatantly obvious for the experts but for newbs like me its a fantastic starting point. inputform.php inputdata.php Once you make these two php pages you'll need to create a folder named upload in the same location as your two php files. You also need to change the permissions of your newly created upload folder to allow public visitors to upload to site. -
Loading images to mySQL using a PHP form?
webmaster1 replied to webmaster1's topic in PHP Coding Help
I've just read through five or six different tutorials on how to upload an image but I simply can not get my head around. I haven't been this frustrated in a long time ??? To clarify I need my form to SIMUTANEOUSLY do the following: [*]Insert my text fields to a database [*]Upload three images into designated directory e.g. /images [*]Insert the url of the images into THE SAME DATABASE that my text fields are sent to. [*]Validate the inputted information [*]Redirect the user to an error or success page. Every tutorial that I've researched, aside from not understanding all the code, only partially shows me what I need to be doing. Some show how to upload an image (I can't even get that much working) but don't show me how to write to a database. I just don't know what parts to pick and string together. The database is created. All of my text fields are inserting fine. The three image fields (input type="file") do not have a corrosponding field in mySQL yet because I'm unsure as to whether they need to be VARCHAR for the URLS or something else. Here's my form inputform.php: <html> <head> <title>inputform</title> <link rel="stylesheet" href="productpage.css" type="text/css" /> </head> <body> <h1>inputform</h1><p>Please capitlize your input.</p> <!--INPUT FORM BEGINS HERE--> <form action="inputdata.php" method="post"> <fieldset> <ol> <li> <label for="make">Make:</label> <input type="text" name="make" id="make" class="text"> </li> <li> <label for="model">Model:</label> <input type="text" name="model" id="model" class="text"> </li> <li> <label for="price">Price:</label> <input type="text" name="price" id="price" class="text"> Please input numeric values only. The '€' symbol is automatically appended. DO NOT USE COMMAS! </li> <li> <label for="engine">Engine:</label> <input type="text" name="engine" id="engine" class="text"> </li> <li> <label for="body">Body Type:</label> <input type="text" name="body" id="body" class="text"> </li> <li> <label for="transmission">Transmission:</label> <input type="text" name="transmission" id="transmission" class="text"> </li> <li> <label for="year">Year:</label> <input type="text" name="year" id="year" class="text"> Please enter a four digit number. </li> <li> <label for="colour">Colour:</label> <input type="text" name="colour" id="colour" class="text"> </li> <li> <label for="mileagem">Mileage M:</label> <input type="text" name="mileagem" id="mileagem" class="text"> Please input numeric values only. The 'M' symbol is automatically appended. </li> <li> <label for="mileagekm">Mileage KM:</label> <input type="text" name="mileagekm" id="mileagekm" class="text"> Please input numeric values only. The 'KM' symbol is automatically appended. </li> <li> <label for="owners">Owners:</label> <input type="text" name="owners" id="owners" class="text"> Please input a single digit only. </li> <li> <label for="doors">Doors:</label> <input type="text" name="doors" id="doors" class="text"> Please input a single digit only. </li> <li> <label for="location">Location:</label> <input type="text" name="location" id="location" class="text"> </li> <li> <label for="info">Additional Info:</label> <textarea name="info" id="info"></textarea> </li> <li> <label for="image1">Image 1:</label> <input type="file" name="image1" id="image1"> </li> <li> <label for="image2">Image 2:</label> <input type="file" name="image2" id="image2"> </li> <li> <label for="image3">Image 3:</label> <input type="file" name="image3" id="image3"> </li> <li> <input type="submit" class="submit"> </li> </ol> </fieldset> </form> <!--INPUT FORM ENDS HERE--> </body> </html> Here is my style sheet productpage.css: /* productpage.css */ /* style the surrounding fieldset border */ fieldset { position:relative; left:0px; top:0px; margin: 0 0 0 0; padding: 0px; border-style:inset; width:1200px; } /* style the overall list, only necessary if more than one list is being used */ fieldset ol { padding-top:20px; list-style: none; } /* style the individual items within the list */ fieldset li { padding-bottom:10px; } /* style labels and align them */ label { float: left; width:90px; margin-right: 10px; font-family:Trebuchet MS, Arial; font-size:12px; } /* style text boxes */ input.text { line-height:12px; font-family:Trebuchet MS, Arial; font-size:12px; color:#999999; border: 1px solid #888377; width: 150px; height:18px; } /* style dropdown */ .dropdown { width: 70px; } /* style button and align it */ input.submit{ position:relative; top:5px; left:100px; width:100px; } Here is my process form inputdata.php <?php // Pick up the form data and assign it to variables $make = $_POST['make']; $model = $_POST['model']; $price = $_POST['price']; $engine = $_POST['engine']; $body = $_POST['body']; $tranmission = $_POST['transmission']; $year = $_POST['year']; $colour = $_POST['colour']; $mileagem = $_POST['mileagem']; $mileagekm = $_POST['mileagekm']; $owners = $_POST['owners']; $doors = $_POST['doors']; $location = $_POST['location']; $info = $_POST['info']; // Additional variables not posted from form $now_datetime = date('Y-m-d h:i:s'); $ipaddress = getenv('REMOTE_ADDR'); // Connect to database include("dbinfo.php"); mysql_connect(localhost,$username,$password); @mysql_select_db($database) or die( "Unable to establish a connection to database."); // Insert into database $query = "INSERT INTO test VALUES ('','$make','$model','$price','$engine','$body','$transmission','$year,','$colour','$mileagem','$mileagekm','$owners','$doors','$location','$info','$now_datetime','$ipaddress')"; mysql_query($query); // Close connection mysql_close(); // Redirect to confirmation page header("Location: success.html"); ?> I know I could have the client upload the images via ftp and manually type in the url of the images into my database via my form but I want to minimise the task for them as much as possible. I want the url and my text fields to be posted and my images to be uploaded simutaneously. I'm bummed out because I really want to figure out the majority of the code for myself so I could post it back to you guys to focus on validating the user input but I obviously I couldn't even get that far. Here are the main tutorials that I researched but cannot implement: http://www.reconn.us/file_uploading.html http://www.webdeveloper.com/forum/showthread.php?t=101466 I would really apreciate any help with this (As you can tell I'm trying to avoid loading images directly to mySQL). -
Loading images to mySQL using a PHP form?
webmaster1 replied to webmaster1's topic in PHP Coding Help
Thanks guys, still working on the code. Will post it later this evening. -
Loading images to mySQL using a PHP form?
webmaster1 replied to webmaster1's topic in PHP Coding Help
Will cunoodle2's code suffice if I'll only have a maximum of 30 images at any one time in my database. -
[SOLVED] Inserting IP ADDRESS into mySQL using a PHP form
webmaster1 replied to webmaster1's topic in PHP Coding Help
Wow, that was simple. Works fine now, thanks!