我的代码有问题吗? 我做得很好,但仍然无法上传图片 恐怖没有显示任何东西,这就是为什么我如此混淆问题所在 请帮帮我
这是我的表格
<form id="form1" name="form1" enctype="multipart/form-data" method="post" action="save_register.php">
这是我的php
<?php
include 'connection.php';
if(isset($_POST['action']))
{
$email=$_POST['email'];
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];
$password1=$_POST['password1'];
$password2=$_POST['password2'];
$gender=$_POST['gender'];
$bday = $_POST['day'];
$bmonth = $_POST['month'];
$byear = $_POST['year'];
$countrys = $_POST['country'];
$avatar=$_POST['avatar'];
if($email=='' || $first_name=='' || $password1=='' || $password2=='' || $gender=='' || $bday=='' || $bmonth=='' || $byear=='' || $countrys=='')
{echo '<h2>Maaf, data Anda tidak lengkap</h2>';}else
{if($password1!=$password2){
echo '<h2>Password Anda tidak sama!</h2>';}
else
//cek data sudah tersedia
{
$sql = "SELECT count(*) as cek FROM `user_login` WHERE email = '".$admin."'";
//echo $sql;
$ambil_data = mysql_query($sql);
if($data = mysql_fetch_array($ambil_data))
{
$cek = 0;
$cek = $data["cek"];
}
//jika data sudah ada
if ($cek==1)
echo "Data already exist";
else //Proses simpan
{
//upload image
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".",$_FILES["file"]["name"]);
$extension = end($temp);
if((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png") || ($_FILES["file"]["type"] == "image/png"))
|| ($_FILES["file"]["type"] == "")
&&($_FILES["file"]["size"] >=0) || ($_FILES["file"]["size"]<200000)
&& in_array($extension, $allowedExts))
{
//cek file upload
if ($_FILES["file"]["error"]==0)
{
echo $_FILES["file"]["name"]."<br>";
echo "Upload: ". $_FILES["file"]["name"]. "<br>";
echo "Type: ". $_FILES["file"]["name"]. "<br>";
echo "Size: ". ($_FILES["file"]["size"] / 1024). "kB<br>";
echo "Temp file: ". $_FILES["file"]["name"]. "<br>";
if(file_exists("image/".$_FILES["file"]["name"]))
{
echo"<tr><td>".$_FILES["file"]["name"]."Please Rename Your File.</td></tr>";
}
else
{
$sql = "INSERT INTO user_login (email, first_name, last_name, password, gender, b_day, b_month, b_year, country, image) VALUES
('$email', '$first_name', '$last_name', '$password1', '$gender', '$bday', '$bmonth', '$byear', '$countrys','$avatar')";
//echo $sql;
$result=@mysql_query($sql)or die(mysql_error());
if($result)
{
echo '<h2>Registration Success</h2><br><a href="login.php">Continue Login</a>';
}else
{
echo '<h2>Error, tidak bisa menyimpan data ke database</h2>';
}
}
}
}
}
}
} }
?>
抱歉,这是我的HTML
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Registration</title>
<link rel="stylesheet" type="text/css" href="all.css">
<body background="image/background.jpg">
<?php include('header.php'); ?>
<table border="1" width="80%" height="500" align="center" bgcolor="#FBFBEF" ><form id="form1" name="form1" enctype="multipart/form-data" method="post" action="save_register.php">
<tr>
<td widht="20" align="center" valign="top" id="loginform"><strong><font size="10"> Register Form</font></strong>
<table border="1" width="60%" height="150" align="center" >
<tr>
<td valign="top" colspan="3"><strong>Account Information</strong></td>
</tr>
<tr>
<td align="center" colspan="3" ><table border="1" bgcolor="white" width="100" height="100" ><tr><td align="center"><input name="avatar" type="hidden" value="avatar/profil.jpg" /><img src="avatar/profil.jpg" ></tr></td></table></td>
</tr>
<tr>
<td colspan="3"><Input type="file" name="file"/></td>
</tr>
<tr>
<td valign="top" width="50%">Email</td><td>:</td><td><input name="email" type="text" id="email" /></td>
</tr>
<tr>
<td valign="top">Password</td><td>:</td><td><input name="password1" type="password" id="password1" /></td>
</tr>
<tr>
<td valign="top">Retype Password</td><td>:</td><td><input name="password2" type="password" id="password2" /></td>
</tr>
<tr>
<td valign="top" colspan="3"><strong>Personal Information</strong></td>
</tr>
<tr>
<td valign="top">First Name</td><td>:</td><td><input name="first_name" type="text" id="first_name" /></td>
</tr>
<tr>
<td valign="top">Last Name</td><td>:</td><td><input name="last_name" type="text" id="last_name" /></td>
</tr>
<tr>
<td valign="top">Gender</td><td>:</td><td><font color="green"><input type="radio" name="gender" checked value="Male"> Male<input type="radio" name="gender" value="Female"> Female </font></td>
</tr>
<tr>
<td valign="top">Birthday</td><td>:</td>
<td width="65%" >
<select name="day">
<option value="-">-</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
</td>
</tr>
<tr>
<td valign="top">Country</td><td>:</td>
<td width="65%" >
<select name="country">
<option value="">Country</option>
<option value="Afganistan">Afghanistan</option>
<option value="Albania">Albania</option>
<option value="Algeria">Algeria</option>
</select>
</td>
</tr>
<tr>
<td colspan="3" align="center"><input type="submit" name="Submit" value="Register" /></td>
</tr>
</table>
</td>
<td rowspan="2" widht="30%" align="center"><img src="image/dotareg.png" width="400" height="450" ></td>
</tr>
</form>
</table>
</font>
</body>
<?php include('footer.php'); ?>
</head>
</html>