Jump to content

[SOLVED] data not passing through $_POST....i think


riceje7

Recommended Posts

hey i'm having a problem uploading image files in a simple registration form i'm making. it seems, as far as i can tell, that the form data for $_POST['image'] is not being passed through and is causing my script to fail at the mime type check. any ideas? here is the corresponding code:

<?php
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
$email = $_POST['email'];
$zip = $_POST['zip'];
$image = $_FILES['image'];
$imagename = $_FILES['image']['name'];
$imagename = str_replace(' ', '_', $imagename);
echo $imagename;

if(isset($username))
{	
$connect = mysql_connect(localhost, $user, $pass);
$db = mysql_select_db(user_data);

$sql = "SELECT * FROM user_data WHERE username='$username'";
$result = mysql_query($sql);
$num = mysql_num_rows($result);
//echo $num;

if($num == 0)
{
	$sql = "INSERT INTO `user_data`.`user_data` (`id`, `username`, `password`, `email`, `zipcode`, `picture_name`) VALUES (NULL, '$username', '$password', '$email','$zip', '$imagename');";
	mysql_query($sql);
	echo "<center>Registration Successful</center>";
}
else
{
	echo "<center>Username Already Taken.</center>";
}

$imageinfo = getimagesize($image); 
if($imageinfo['mime'] != 'image/gif' && $imageinfo['mime'] != 'image/jpeg' && $imageinfo['mime'] != 'image/jpe' && $imageinfo['mime'] != 'image/jpg')
{ 
    	echo "That is an invalid file type, you must upload either a JPEG or GIF file.\n Please use your browser's 'Back' button and try again.\n"; 
   		exit; 
} 

$uploaddir = "user_images/"; 
$uploadfile = $uploaddir.basename($imagename); 
if (move_uploaded_file($image, $uploadfile)) { 
    	echo "File Upload Successful.\n";}
}




?>
<html>
<head>
<link REL="SHORTCUT ICON" HREF="favicon.ico">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
</head>

<body>

<table width="300" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
<tr>
<form name="form1" method="post" action="register.php">
<td>
<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
<tr>
<td colspan="3" align="center"><strong>Member Registration </strong></td>
</tr>
<tr>
<td width="78">Username</td>
<td width="6">:</td>
<td width="294"><input name="username" type="text" id="username"></td>
</tr>
<tr>
<td>Password</td>
<td>:</td>
<td><input name="password" type="password" id="password"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="email" type="text" id="email"></td>
</tr>
<tr>
<td>Zipcode</td>
<td>:</td>
<td><input name="zip" type="text" id="zip"></td>
</tr>
<tr>
<td>Image</td>
<td>:</td>
<td><input name="image" type="file" id="image"></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td align="right"><input type="submit" name="Submit" value="Register"></td>
</tr>
</table>
</td>
</form>
</tr>
</table>
</body>
</html>

Link to comment
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.