如何在现有的上传图像中添加注册表单代码


how to add register form code in existing upload image

这是我的代码:

     <html>
<head>
<title>upload images to database</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<h1>Register Form</h1>
<form class = "form" action="backup.php" method = "POST" enctype = "multipart/form-data">
Upload Photo:<input type= "file" name= "image"><br />
Firstname:<input type = "text" name = "fname"><br />
Lastname:<input type = "text" name = "lname"><br />
Password:<input type = "text" name = "password"><br />
Retype-password:<input type = "text" name = "rpassword"><br />
Email:<input type = "text" name = "email"><br />
Address:<input type = "text" name = "address"><br />
Phone:<input type = "text" name = "phone"><br />
<input type= "submit" class = "submit" value= "upload">
</form>
<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
//connect to database
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("image") or die(mysql_error());
$file = '';
$file= $_FILES['image']['tmp_name'];
$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$password = $_POST['password'];
$rpassword = $_POST['rpassword'];
 if(!isset($file))
 {
 echo "please select an image";
 }
 else
 {
$image = mysql_real_escape_string(file_get_contents($_FILES['image']['tmp_name']));
$image_name = mysql_real_escape_string($_FILES['image']['name']);
$image_size = getimagesize($_FILES['image']['tmp_name']);
if($image_size ==FALSE)
{
echo "That's not an image";
}
else
    {
    if(!$insert = mysql_query("INSERT INTO upload VALUES('','$image_name','$image','$firstname','$lastname','$email','$address','$password','$rpassword')"))
    {
    echo "Problem uploading image";
    }
    else{
    $lastid = mysql_insert_id();
    echo "Image upload.<p/>Your Image</p><img src=get.php?id=$lastid>";
    }
} 
 }
}
?>
</body>
</html>

这是我的php代码上传图像和存储在数据库中,也显示在主页。

现在它工作得很好,我想为额外的字段添加代码,如名字,姓氏…等等,比如注册表

这里我需要为注册表单添加代码。

有人能帮我吗?

你应该使用$_POST方法因为你有action="POST"在你的表单html它发送数据到服务器使用post请求

添加到html

<form action="index.php" method = "POST" enctype = "multipart/form-data">
    First Name: <input type = "text" name= "fname"><br />
    Last Name:<input type = "text" name= "lname"><br />
    Password :<input type = "text" name = "password"><br />
    Retype-password: <input type = "text" name = "rpassword"><br />
    Email:<input type = "text" name = "email"><br />
    Phone Num: <input type = "text" name = "phone"><br />
    Address: <input type ="text" name = "address"><br />
    ...... some your html 
</form>

获取服务器数据

$firstname = $_POST['fname'];
$lastname = $_POST['lname'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$password = $_POST['password'];
$rpassword = $_POST['rpassword'];

看这个教程