Jump to content

Recommended Posts

Hello everyone,

 

I'm creating a user information form which includes an image uploader as well as several text inputs.

 

The problem is with...

 

<form  ENCTYPE = "multipart/form-data"></form>

 

When I have ENCTYPE set to multipart/form-data the image uploader works but not the text inputs.

 

When its not set text inputs work but image uploader doesn't work.

 

Anyone have insight into why this is and a good solution?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/
Share on other sites

Ok its lengthy...

 

Keep in mind the ENCTYPE is not set currently

 

HTML FORM

			<div id="frontpage" align="center">

            <form  action="edituser.php?user=<?php echo $user_row['user_id'];  ?>" method="post" name="edituser" id="edituser">
  <h3><u>Edit your ad</u></h3>
  
   <p style="color:red;"><?php echo $_SESSION['error'];
									echo $_SESSION['error']=NULL;
		 ?></p>
  
  <table align="center">
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Name:</td>
      <td><input type="text" name="user_name" id="user_name" value="<?php echo $user_row['user_name'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Province:<br/><br/>City:</td>
      <td>
      <select name="user_province" id="user_province">
        <option value="Border States" <?php if($user_row['user_province']=="Border States") { echo " selected=\"selected\" "; } ?>>Border States</option>
      	<option value="British Columbia" <?php if($user_row['user_province']=="British Columbia") { echo " selected=\"selected\" "; } ?>>British Columbia</option>
        <option value="Alberta" <?php if($user_row['user_province']=="Alberta") { echo " selected=\"selected\" "; } ?>>Alberta</option>
        <option value="Saskatchewan" <?php if($user_row['user_province']=="Saskatchewan") { echo " selected=\"selected\" "; } ?>>Saskatchewan</option>
        <option value="Manitoba" <?php if($user_row['user_province']=="Manitoba") { echo " selected=\"selected\" "; } ?>>Manitoba</option>
        <option value="Ontario" <?php if($user_row['user_province']=="ontario") { echo " selected=\"selected\" "; } ?>>Ontario</option>
        <option value="Quebec" <?php if($user_row['user_province']=="Quebec") { echo " selected=\"selected\" "; } ?>>Quebec</option>
        <option value="Nova Scotia" <?php if($user_row['user_province']=="Nova Scotia") { echo " selected=\"selected\" "; } ?>>Nova Scotia</option>
        <option value="New Brunswick" <?php if($user_row['user_province']=="New Brunswick") { echo " selected=\"selected\" "; } ?>>New Brunswick</option>
        <option value="Newfoundland and Labrador" <?php if($user_row['user_province']=="Newfoundland and Labrador") { echo " selected=\"selected\" "; } ?>>Newfoundland and Labrador</option>
        <option value="Prince Edward Island" <?php if($user_row['user_province']=="Prince Edward Island") { echo " selected=\"selected\" "; } ?>>Prince Edward Island</option>
        <option value="Northwest Territories" <?php if($user_row['user_province']=="Northwest Territories") { echo " selected=\"selected\" "; } ?>>Northwest Territories</option>
        <option value="Yukon" <?php if($user_row['user_province']=="Yukon") { echo " selected=\"selected\" "; } ?>>Yukon</option>
        <option value="Nunavut" <?php if($user_row['user_province']=="Nunavut") { echo " selected=\"selected\" "; } ?>>Nunavut</option>
      </select>
      <input type="text" name="user_area" id="user_area" value="<?php echo $user_row['user_area'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Phone:</td>
      <td><input type="text" name="user_phone" id="user_phone" value="<?php echo $user_row['user_phone'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Email:</td>
      <td><input type="text" name="user_email" id="user_email" value="<?php echo $user_row['user_email'];   ?>" size="32" /></td>
    </tr>    
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Website:</td>
      <td><input type="text" name="user_website" id="user_website" value="<?php echo $user_row['user_website'];   ?>" size="32" /></td>

      <td align="right" valign="top" nowrap="nowrap">Measurements:</td>
      <td><input type="text" name="user_mesurements" id="user_mesurements" value="<?php echo $user_row['user_measurements'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Age:</td>
      <td><input type="text" name="user_age" id="user_age" value="<?php echo $user_row['user_age'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Hair:</td>
      <td><input type="text" name="user_hair" id="user_hair" value="<?php echo $user_row['user_hair'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Eyes:</td>
      <td><input type="text" name="user_eyes" id="user_eyes" value="<?php echo $user_row['user_eyes'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Height:</td>
      <td><input type="text" name="user_height" id="user_height" value="<?php echo $user_row['user_height'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Weight:</td>
      <td><input type="text" name="user_weight" id="user_weight" value="<?php echo $user_row['user_weight'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Services:</td>
      <td><input type="text" name="user_services" id="user_services" value="<?php echo $user_row['user_services'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Clients:</td>
      <td><input type="text" name="user_clients" id="user_clients" value="<?php echo $user_row['user_clients'];   ?>" size="32" /></td>

      <td nowrap="nowrap" align="right">Rates:</td>
      <td><input type="text" name="user_rates" id="user_rates" value="<?php echo $user_row['user_rates'];   ?>" size="32" /></td>
    </tr>
    <tr valign="baseline">
      <td nowrap="nowrap" align="right">Availability:</td>
      <td><input type="text" name="user_availability" id="user_availability" value="<?php echo $user_row['user_availability'];   ?>" size="32" /></td>
      <td nowrap="nowrap" align="right">Upload Image<br/><a href="#images" onClick="getElementById('edit-images').style.visibility='visible', getElementById('edit-images').style.height='inherit'">(edit images)</a></td>
      <td><input type="file" name="uploaded_file" /></td>
    </tr>
      <tr valign="baseline">
      <td colspan="4" style="text-align:center;"><div id="edit-images" style="visibility:hidden; height:0px;"><a name="images"/><b>Images</b> <a href="#" onClick="getElementById('edit-images').style.visibility='hidden', getElementById('edit-images').style.height='0px'">(hide)</a></div></td>
    </tr>
              <tr valign="baseline">
      <td colspan="4" style="text-align:center;"><p><b>Message</b></p><textarea name="user_message" id="user_message" style="width:85%; height:200px;"><?php echo $user_row['user_message'];  ?></textarea>
      </td>
    </tr>
    <tr valign="baseline">
      <td colspan="4"><div align="center">
        <input id='form_submit' class="submit" type="submit" value=''/>
      </td>
      </div>
    </tr>
  </table>
</form>	
        						
		</div><!--end frontpage-->

 

Processing Code

<?php
require_once("connect.php");
session_start();

$user_string = mysql_query("SELECT * FROM tbl_users WHERE user_id='".$_SESSION['id']."'"); 
$user_row = mysql_fetch_array($user_string);
$user_level = $user_row['user_level'];

if(!isset($_SESSION['id'])) {
header("Location: login.php");
}

require_once("connect.php");
$user = $_GET['user'];

$name = mysql_real_escape_string($_POST['user_name']);
$area = mysql_real_escape_string($_POST['user_area']);
$phone = mysql_real_escape_string($_POST['user_phone']);
$email = mysql_real_escape_string($_POST['user_email']);
$website = mysql_real_escape_string($_POST['user_website']);
$mesurements = mysql_real_escape_string($_POST['user_mesurements']);
$age = mysql_real_escape_string($_POST['user_age']);
$hair = mysql_real_escape_string($_POST['user_hair']);
$eyes = mysql_real_escape_string($_POST['user_eyes']);
$height = mysql_real_escape_string($_POST['user_height']);
$weight = mysql_real_escape_string($_POST['user_weight']);
$services = mysql_real_escape_string($_POST['user_services']);
$clients = mysql_real_escape_string($_POST['user_clients']);
$rates = mysql_real_escape_string($_POST['user_rates']);
$availability = mysql_real_escape_string($_POST['user_availability']);
$message = mysql_real_escape_string($_POST['user_message']);
$province = mysql_real_escape_string($_POST['user_province']);

//Check to see if the user is uploading an image.

if($_FILES["uploaded_file"]["name"]!="") {

// This value sets where you go when an error occurs
if($user_level==3) { $exit_to = "users.php"; } else { $exit_to = "create.php"; }

// START IMAGE UPLOADING CODE

// Access the $_FILES global variable for this specific file being uploaded
// and create local PHP variables from the $_FILES array of information
$fileName = $_FILES["uploaded_file"]["name"]; // The file name
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"]; // File in the PHP tmp folder
$fileType = $_FILES["uploaded_file"]["type"]; // The type of file it is
$fileSize = $_FILES["uploaded_file"]["size"]; // File size in bytes
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; // 0 = false | 1 = true
$kaboom = explode(".", $fileName); // Split file name into an array using the dot
$fileExt = end($kaboom); // Now target the last array element to get the file extension


// START PHP Image Upload Error Handling --------------------------------------------------

if (!$fileTmpLoc) { // if file not chosen
    $_SESSION['error'] = "ERROR: Please browse for a file before clicking the upload button.";
    header("Location: ".$exit_to);
exit();
} else if($fileSize > 5242880) { // if file size is larger than 5 Megabytes
    $_SESSION['error'] = "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
    header("Location: ".$exit_to);
exit();
} else if (!preg_match("/\.(gif|jpg|png)$/i", $fileName) ) {
     // This condition is only if you wish to allow uploading of specific file types    
     $_SESSION['error'] = "ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
     header("Location: ".$exit_to);
 exit();
} else if ($fileErrorMsg == 1) { // if file upload error key is equal to 1
    $_SESSION['error'] = "ERROR: An error occured while processing the file. Try again.";
    header("Location: ".$exit_to);
exit();
}

// END PHP Image Upload Error Handling ----------------------------------------------------
// Place it into your "uploads" folder mow using the move_uploaded_file() function
if(!file_exists("uploads/".$user."/")) {
  if(!mkdir("uploads/".$user)) 
  $_SESSION['error'] = "Failed creating user directory.";
    header("Location: ".$exit_to);
}
$date_filename = date('mdi')."-".$fileName;
$upload_location = "uploads/".$user."/".$date_filename;
$moveResult = move_uploaded_file($fileTmpLoc, $upload_location);
// Check to make sure the move result is true before continuing
if ($moveResult != true) {
    $_SESSION['error'] = "ERROR: File not uploaded. Try again.";
    unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder
    header("Location: ".$exit_to);
exit();
}

//Create a database entry for the Image!!!

$image_string = "INSERT INTO tbl_images VALUES(NULL,'".$date_filename."','".$user."')";
$image_result = mysql_query($image_string);


unlink($fileTmpLoc); // Remove the uploaded file from the PHP temp folder

// ---------- Include Adams Universal Image Resizing Function --------
include_once("libraries/ak_php_img_lib_1.0.php");
$target_file = $upload_location;
$resized_file = $upload_location;
$resized_file2 = "uploads/".$user."/th_".$date_filename;
$wmax = 340;
$wmax2 = 150;
$hmax = 340;
$hmax2 = 150;
ak_img_resize($target_file, $resized_file, $wmax, $hmax, $fileExt);
ak_img_resize($target_file, $resized_file2, $wmax2, $hmax2, $fileExt);
// ----------- End Adams Universal Image Resizing Function -----------


// END IMAGE UPLOADING CODE

}



if($user_level==3 & $_POST{'user_username'}!="" & $_POST{'user_password'}!="" & $_POST{'user_level'}!="" & $_POST{'user_on'}!="") {
$username = mysql_real_escape_string($_POST{'user_username'});
$password = mysql_real_escape_string($_POST{'user_password'});
$level = mysql_real_escape_string($_POST['user_level']); 
$on = mysql_real_escape_string($_POST['user_on']); 
}

if($user_level==3 & $_POST{'user_username'}!="" & $_POST{'user_password'}!="" & $_POST{'user_level'}!="" & $_POST{'user_on'}!="") {
$updatestring = "UPDATE tbl_users SET user_username='".$username."', user_password='".$password."', user_level='".$level."',user_on='".$on."',user_name='".$name."',user_area='".$area."',user_phone='".$phone."',user_email='".$email."',user_website='".$website."',user_measurements='".$mesurements."',user_age='".$age."',user_hair='".$hair."',user_eyes='".$eyes."',user_height='".$height."',user_weight='".$weight."',user_services='".$services."',user_clients='".$clients."',user_rates='".$rates."',user_availability='".$availability."',user_message='".$message."',user_province='".$province."' WHERE user_id=".$user;
$update_results = mysql_query($updatestring);
header("Location: users.php");
} else {
$updatestring = "UPDATE tbl_users SET user_name='".$name."',user_area='".$area."',user_phone='".$phone."',user_email='".$email."',user_website='".$website."',user_measurements='".$mesurements."',user_age='".$age."',user_hair='".$hair."',user_eyes='".$eyes."',user_height='".$height."',user_weight='".$weight."',user_services='".$services."',user_clients='".$clients."',user_rates='".$rates."',user_availability='".$availability."',user_message='".$message."',user_province='".$province."' WHERE user_id=".$user;
$update_results = mysql_query($updatestring);
header("Location: ad.php?id=$user");
}



?>

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/#findComment-1204564
Share on other sites

A google search for "enctype problem php" or "enctype POST" will bring up many results of people having similar problems.

 

A few examples

 

http://www.mombu.com/php/php/t-26004-post-variables-not-set-when-using-enctypemultipartform-data-965455-last.html

 

http://www.gidforums.com/t-6614.html

 

http://forums.devshed.com/apache-development-15/enctype-multipart-form-data-a-problem-14785.html

 

All reports say the same thing as soon as ENCTYPE is set to multipart/form-data the form processing stops working.

 

I've been reading page after page and still no solution...

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/#findComment-1204633
Share on other sites

Your form works for me (after adding enctype="multipart/form-data") in FF4 and IE8.

 

What does the following show, after the form has been submitted -

 

echo "<pre>";
echo "GET:";
print_r($_GET);
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/#findComment-1204648
Share on other sites

Your form works for me (after adding enctype="multipart/form-data") in FF4 and IE8.

 

What does the following show, after the form has been submitted -

 

echo "<pre>";
echo "GET:";
print_r($_GET);
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

 

I included the echo commands at the very end of edituser.php and got back...

 

GET:Array
(
    [user] => 1
)
POST:Array
(
)
FILES:Array
(
)

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/#findComment-1204689
Share on other sites

I'm having all kinds of problems editing my php.ini , I had to totally reset it.

 

Reason being I was editing it and expecting effects but I didn't realize you had to restart for the change to take effect.

 

Could you post the contents of your php.ini since the code seems to be working on your machine.

 

NEVER mind I reset php.ini and changed post_max_size and everything is now working, thanks to everyone who replied

Link to comment
https://forums.phpfreaks.com/topic/234372-problem-with-form/#findComment-1204704
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.