dare87 Posted January 22, 2008 Share Posted January 22, 2008 I am making an audition form but I don't know how to make it so they can upload a photo with the form. I have the HTML portion of what I think it would be, but I am still new at this. any help will be great. Here is the code. Also if there is an easy way to make the radio button sticky that would be great too.. Thanks again <?php // Include the PHP script that contains the session information. include('includes/session.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Humor us | Audition Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="includes/base.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="includes/include.js"></script> </head> <body> <div id="box"> <div id="header"> <?php include('includes/header.php'); ?> </div> <div id="main"> <div id="sideBarLeft"> <?php include('includes/left.php'); ?> </div> <div id="content"> <div class="maintitle"> Audition Form </div> <?php if (isset($_POST['submit'])) // The form has been submitted. { // Initialize an error array to contain any error messages. $errors = array(); // Check for a first name. if (!empty($_REQUEST['firstname'])) $firstname = $_REQUEST['firstname']; else $errors[] = 'Please enter your first name.'; // Check for a last name. if (!empty($_REQUEST['lastname'])) $lastname = $_REQUEST['lastname']; else $errors[] = 'Please enter your last name.'; // Check for a last name. if (!empty($_REQUEST['mainphone'])) $mainphone = $_REQUEST['mainphone']; else $errors[] = 'Please enter your main phone number.'; // Check for a last name. if (!empty($_REQUEST['secondphone'])) $secondphone = $_REQUEST['secondphone']; // Check for a last name. if (!empty($_REQUEST['email'])) $email = $_REQUEST['email']; else $errors[] = 'Please enter your email address.'; // Check for a last name. if (!empty($_REQUEST['experiance'])) $experiance = $_REQUEST['experiance']; else $errors[] = 'Please enter your experiance.'; // Check for a last name. if (!empty($_REQUEST['deserve'])) $deserve = $_REQUEST['deserve']; else $errors[] = 'Please enter why you deserve to be on the cast.'; // Check for a last name. if (!empty($_REQUEST['oneday'])) $oneday = $_REQUEST['oneday']; else $errors[] = 'Please enter what you would do on your last day alive.'; // Check for a last name. if (!empty($_REQUEST['perform'])) $perform = $_REQUEST['perform']; // Check for agree. if (!empty($_REQUEST['agree'])) $agree = $_REQUEST['agree']; else $errors[] = 'You Must agree to submit an audition form.'; // If there are no errors, add the user to the database. if (empty($errors)) { // Connect to the databse. require_once ('../../pimysql_connect.php'); // Add the query. $query = "INSERT INTO audition SET firstname='$firstname', lastname='$lastname', mainphone='$mainphone', secondphone='$secondphone', email='$email', experiance='$experiance', deserve='$deserve', oneday='$oneday', perform='$perform', agree='$agree'"; // Run the query. $results = mysql_query($query); // If there are no errors. if ($results) echo 'Thank you. Your Audition form has been submitted.'; else echo '<div class="error">An error occured. Your Audition form was not submitted.</div>'; } else foreach ($errors as $msg) echo '<div class="error"> - ' . $msg . '</div>'; } ?> <form name="audition" action="audition.php" method="post"> <table width="588" style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana,Arial,Helvetica,Serif; BORDER-COLLAPSE: collapse"> <!--Audition Form--> <tr> <td width="158" align="right">First Name:</td> <td width="17"></td> <td width="397" align="left"><input type="text" class="required" name="firstname" id="focus" size="22" value="<?php echo $firstname; ?>" maxlength="15"></td> </tr> <tr> <td align="right">Last Name:</td> <td width="17"></td> <td align="left"><input type="text" name="lastname" id="focus" size="22" value="<?php echo $lastname; ?>" maxlength="15"></td> </tr> <tr> <td align="right">Main Number:</td> <td width="17"></td> <td align="left"><input type="text" class="required" name="mainphone" id="focus" size="22" value="<?php echo $mainphone; ?>" maxlength="12"></td> </tr> <tr> <td align="right">Secondary Number:</td> <td width="17"></td> <td align="left"><input type="text" name="secondphone" id="focus" size="22" value="<?php echo $secondphone; ?>" maxlength="12"></td> </tr> <tr> <td align="right">Email:</td> <td width="17"></td> <td align="left"><input type="text" name="email" id="focus" size="22" value="<?php echo $email; ?>" maxlength="40"></td> </tr> <tr> <td align="right">Photo:</td> <td width="17"></td> <td><input type="hidden" name="MAX_FILE_SIZE" value="5000000"><input type="file" name="photo" value="'.$photo.'"> <br>Max upload 5mb</td> </tr> <tr> <td align="right">Previous Acting<br>Experiance:</td> <td width="17"></td> <td align="left"><textarea class="required" name="experiance" rows="5" cols="35"><?php echo $experiance; ?></textarea></td> </tr> <tr> <td align="right">Why do you deserve<br>to be in the cast?</td> <td width="17"></td> <td align="left"><textarea class="required" name="deserve" rows="5" cols="35"><?php echo $deserve; ?></textarea></td> </tr> <tr> <td align="right">If you had one day to live,<br> what would you do?</td> <td width="17"></td> <td align="left"><textarea class="required" name="oneday" rows="5" cols="35"><?php echo $oneday; ?></textarea></td> </tr> <tr> <td align="right">Can you perform two<br>Fridays a month?</td> <td width="17"></td> <td align="left"><input type="radio" value="yes" name="perform"> YES<br><input type="radio" value="no" name="perform"> NO</td> </tr> <tr> <td colspan="3"><br><br><center>SEE TERMS AND CONDITIONS</center><br><br></td> </tr> <tr> <td align="right">Do you agree to the terms?</td> <td width="17"></td> <td align="left">YES:<input type="checkbox" value="Yes" name="agree"></td> </tr> <tr> <td><br><br><input type="submit" class="button" name="submit" value="Submit"></td> <td> </td> <td> </td> </tr> <tr> <td colspan="3" class="smallText">* Highlighted forms designate required fields.</td> </tr> </table> </div> </form> <div id="bottom"> <?php include('includes/bottom.php'); ?> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/ Share on other sites More sharing options...
naveenbj Posted January 22, 2008 Share Posted January 22, 2008 Hello http://www.w3schools.com/php/php_file_upload.asp Hope this lik will help you for what you want... Nj Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445859 Share on other sites More sharing options...
NikkiLoveGod Posted January 22, 2008 Share Posted January 22, 2008 Hi there! I can recommend this PDF about uploading pictures. It's very simple, but still explains alot of the securityholes in the form and picture itself. I used this one for a project of mine; http://www.scanit.be/uploads/php-file-upload.pdf Good luck! -NikkiLoveGod Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445865 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 My only problem is I don't know how to implement this into my current code. I have done the rest of examples that I have found, but I have yet been able to implement the file upload. I have tried, but failed every time. Thanks for the links, and I will keep trying, but any more help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445880 Share on other sites More sharing options...
NikkiLoveGod Posted January 22, 2008 Share Posted January 22, 2008 Well, first you add a new inputfield into your form, with type="file" and then you put up a code into your php section where you check if the image has been uploaded, and if it has and it meets the requirements, you move it to some folder on your server, and for example, put its link into a database of yours. Check the pdf, there is a simple guide. Remember to put the ENCTYPE="multipart/formdata" into the form, that should help too Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445882 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 I have add this <?php if (isset($_FILES['upload']) && ($_FILES['upload']['error'] != 4)) { $upload = $_FILES['upload']; $upload_option = TRUE; } else { $upload_option = FALSE; }?> But I am still having trouble with how/where to add the temp file and such to a db. I wrote this but I don't know how to still have the rest of my data inputed into my other db <?php // If the user decided to upload a file the following script will run. if ($upload_option == TRUE) { // Connect to the database. require_once ('../../pimysql_connect.php'); // Create a variable that will contain the description information for this upload. // For uploads from the contact page the description will consist of the users name. $description = 'Uploaded by ' . $name . ', ' . $email; // Make the query. $query = "INSERT INTO uploads (file_name, file_size, file_type, description, user) VALUES ('{$_FILES['upload']['name']}' , '{$_FILES['upload']['size']}' , '{$_FILES['upload']['type']}' , '$description' , 'contact')"; // Run the query. $result = mysql_query ($query); // Rename the file user the user_id before it is moved into the uploads directory. if ($result) { $upload_id = mysql_insert_id(); } // Move the file to its new location on the server. if (move_uploaded_file($_FILES['upload']['tmp_name'], "uploads/$upload_id")) { $upload_success = TRUE; } else { $upload_success = FALSE; $query = "DELETE FROM uploads WHERE upload_id = $upload_id"; // If the file could not be moved the database entry will be deleted. $result = mysql_query ($query); } }?> Can someone help me put these two things within my first comment... if not any help will be great. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445886 Share on other sites More sharing options...
NikkiLoveGod Posted January 22, 2008 Share Posted January 22, 2008 umm? Im not sure what you are trying to do there exactly, but you really shouldnt put stuff into your databasequery without escaping it first with, for example mysql_real_escape_string(). http://fi2.php.net/mysql_real_escape_string And to get that imageuploading to work, you need to put up the ' enctype="multipart/formdata" ' into your <form> tag. then you need to insert a <input type="file" name="image" /> into your form, where you have the textareas. Then you put up to your PHP section and if-statement where it checks if the file is uploaded or not. <?PHP if(!empty($_FILE['image']['name'])) { //NOT EMTPY } ?> and in the not empty part you will put up the checks if the file that is uploaded meets the requirements. and then if it meets the requirements, you move it from the temp file to a some folder in your server. <?PHP //this is the folder where the file is uploaded $uploaddir = 'uploads/'; //This is the actual path to the file. $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); //Check if moving of the file is successfull to the appointed folder if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { //And this states that the action was successfull, here you can insert the LINK to the image into the database. echo "File is valid, and was successfully uploaded.\n"; /* This is an example how you can add it to your database. * * $url = "http://SITEURLHERE.COM/"; * $query = "UPDATE table SET imageurl = '" . $url . $uploadfile . "' WHERE id = '" . $SOMEID . "' "; * $result = mysql_query($query) or die("ERROR!"); * * NOTE: add the escapes and modify to your needs. This should work, though im not a master my self. I havent done this that * many times either */ } else { echo "File uploading failed.\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445912 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 Sorry, I am not very good/knowledge in php... this is the code I have... can you show me within my code more of what you mean.. Thanks <?php // Include the PHP script that contains the session information. include('includes/session.php'); ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Humor us | Audition Form</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <link href="includes/base.css" rel="stylesheet" type="text/css"> <script type="text/javascript" src="includes/include.js"></script> </head> <body> <div id="box"> <div id="header"> <?php include('includes/header.php'); ?> </div> <div id="main"> <div id="sideBarLeft"> <?php include('includes/left.php'); ?> </div> <div id="content"> <div class="maintitle"> Audition Form </div> <?php if (isset($_POST['submit'])) // The form has been submitted. { // Initialize an error array to contain any error messages. $errors = array(); // Check for a first name. if (!empty($_REQUEST['firstname'])) $firstname = $_REQUEST['firstname']; else $errors[] = 'Please enter your first name.'; // Check for a last name. if (!empty($_REQUEST['lastname'])) $lastname = $_REQUEST['lastname']; else $errors[] = 'Please enter your last name.'; // Check for a last name. if (!empty($_REQUEST['mainphone'])) $mainphone = $_REQUEST['mainphone']; else $errors[] = 'Please enter your main phone number.'; // Check for a last name. if (!empty($_REQUEST['secondphone'])) $secondphone = $_REQUEST['secondphone']; // Check for email if (empty($_REQUEST['email'])) { $errors[] = 'Please enter an e-mail address.'; } else { // If the user entered an e-mail address check the syntax. if (eregi ('^([_a-z0-9-]+)(\.[_a-z0-9-]+)*@([a-z0-9-]+)(\.[a-z0-9-]+)*(\.[a-z]{2,4})$', $_POST['email'])) { $email = $_REQUEST['email']; } else { $errors[] = 'Please enter a valid e-mail address.'; } } //Check for image if(!empty($_FILE['image']['name'])) { //NOT EMPTY } // Check for a last name. if (!empty($_REQUEST['experiance'])) $experiance = $_REQUEST['experiance']; else $errors[] = 'Please enter your experiance.'; // Check for a last name. if (!empty($_REQUEST['deserve'])) $deserve = $_REQUEST['deserve']; else $errors[] = 'Please enter why you deserve to be on the cast.'; // Check for a last name. if (!empty($_REQUEST['oneday'])) $oneday = $_REQUEST['oneday']; else $errors[] = 'Please enter what you would do on your last day alive.'; // Check for a last name. if (!empty($_REQUEST['perform'])) $perform = $_REQUEST['perform']; // Check for agree. if (!empty($_REQUEST['agree'])) $agree = $_REQUEST['agree']; else $errors[] = 'You Must agree to submit an audition form.'; // If there are no errors, add the user to the database. if (empty($errors)) { // Connect to the databse. require_once ('../../pimysql_connect.php'); // Add the query. $query = "INSERT INTO audition SET firstname='$firstname', lastname='$lastname', mainphone='$mainphone', secondphone='$secondphone', email='$email', experiance='$experiance', deserve='$deserve', oneday='$oneday', perform='$perform', agree='$agree'"; // Run the query. $results = mysql_query($query); // If there are no errors. if ($results) echo 'Thank you. Your Audition form has been submitted.'; else echo '<div class="error">An error occured. Your Audition form was not submitted.</div>'; } else foreach ($errors as $msg) echo '<div class="error"> - ' . $msg . '</div>'; } ?> <form name="audition" action="audition.php" method="post"> <table width="588" style="FONT-SIZE: 8pt; COLOR: black; FONT-FAMILY: Verdana,Arial,Helvetica,Serif; BORDER-COLLAPSE: collapse"> <!--Audition Form--> <tr> <td width="158" align="right">First Name:</td> <td width="17"></td> <td width="397" align="left"><input type="text" class="required" name="firstname" id="focus" size="22" value="<?php echo $firstname; ?>" maxlength="15"></td> </tr> <tr> <td align="right">Last Name:</td> <td width="17"></td> <td align="left"><input type="text" name="lastname" id="focus" size="22" value="<?php echo $lastname; ?>" maxlength="15"></td> </tr> <tr> <td align="right">Main Number:</td> <td width="17"></td> <td align="left"><input type="text" class="required" name="mainphone" id="focus" size="22" value="<?php echo $mainphone; ?>" maxlength="12"></td> </tr> <tr> <td align="right">Secondary Number:</td> <td width="17"></td> <td align="left"><input type="text" name="secondphone" id="focus" size="22" value="<?php echo $secondphone; ?>" maxlength="12"></td> </tr> <tr> <td align="right">Email:</td> <td width="17"></td> <td align="left"><input type="text" name="email" id="focus" size="22" value="<?php echo $email; ?>" maxlength="40"></td> </tr> <tr> <td align="right">Photo:</td> <td width="17"></td> <td><input type="hidden" name="MAX_FILE_SIZE" value="5000000"><input type="file" name="image" value="'.$image.'"> <br>Max upload 5mb</td> </tr> <tr> <td align="right">Previous Acting<br>Experiance:</td> <td width="17"></td> <td align="left"><textarea class="required" name="experiance" rows="5" cols="35"><?php echo $experiance; ?></textarea></td> </tr> <tr> <td align="right">Why do you deserve<br>to be in the cast?</td> <td width="17"></td> <td align="left"><textarea class="required" name="deserve" rows="5" cols="35"><?php echo $deserve; ?></textarea></td> </tr> <tr> <td align="right">If you had one day to live,<br> what would you do?</td> <td width="17"></td> <td align="left"><textarea class="required" name="oneday" rows="5" cols="35"><?php echo $oneday; ?></textarea></td> </tr> <tr> <td align="right">Can you perform two<br>Fridays a month?</td> <td width="17"></td> <td align="left"><input type="radio" value="yes" name="perform"> YES<br><input type="radio" value="no" name="perform"> NO</td> </tr> <tr> <td colspan="3"><br><br><center>SEE TERMS AND CONDITIONS</center><br><br></td> </tr> <tr> <td align="right">Do you agree to the terms?</td> <td width="17"></td> <td align="left">YES:<input type="checkbox" value="Yes" name="agree"></td> </tr> <tr> <td><br><br><input type="submit" class="button" name="submit" value="Submit"></td> <td> </td> <td> </td> </tr> <tr> <td colspan="3" class="smallText">* Highlighted forms designate required fields.</td> </tr> </table> </div> </form> <div id="bottom"> <?php include('includes/bottom.php'); ?> </div> </div> </div> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445918 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 I tried doing it like explained but I am still not getting it. any more help would be great. Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445932 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 Does anyone have a working example of this that they could post? Something that has fields and an upload? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-445933 Share on other sites More sharing options...
dare87 Posted January 22, 2008 Author Share Posted January 22, 2008 I am still having issues getting this code to work. If anyone has more input or an example of a working form that would be great. Quote Link to comment https://forums.phpfreaks.com/topic/87175-upload-img-with-form/#findComment-446195 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.