单击提交按钮时,我的所有数据和图像名称都将进入数据库(使用phpmyadmin),但图像也应该进入名为' uploads'这没有发生。
这是我的注册表格代码blogger_register.php
<?php
require "connect.php";
session_start();
if(isset($_POST['submit']))
{
$target="uploads/".basename($_FILES['image']['name']);
$bname=$_POST['bname'];
$blogname=$_POST['blogname'];
$contact=$_POST['bno'];
$email=$_POST['bmail'];
$blogtype=$_POST['blogtypes'];
$username=$_POST['buser'];
$password=$_POST['bpass'];
$password2=$_POST['bpass2'];
$prooftype=$_POST['prooftypes'];
$proofno=$_POST['proofno'];
$bloglink=$_POST['link'];
$image=$_FILES['image']['name'];
$bio=$_POST['text'];
if($password==$password2)
{
$sql="select * from brg WHERE `buser`='$username'";
$query_run=mysqli_query($conn,$sql);
if(mysqli_num_rows($query_run)>0)
{
echo '<script type="text/javascript"> alert("username already exists") </script>';
}
else
{
$sql="INSERT into `brg` VALUES ('','".$bname."','".$blogname."','".$contact."','".$email."','".$blogtype."','".$prooftype."','".$proofno."','".$username."','".$password."','".$bloglink."','".$image."','".$bio."')";
$query_run=mysqli_query($conn,$sql);
if($query_run)
{
header("Location: dashboard.php");
}
else
{
echo '<script type="text/javascript"> alert("error") </script>';
}
}
}
else
{
echo '<script type="text/javascript"> alert("Password does not match") </script>';
}
}
?>
<!DOCTYPE html>
<html>
<head>
<title>Blogger Registration Form</title>
<style type="text/css">
form {
border: 3px solid #777;
border-radius:20px;
width:60%;
margin-left:20%;
}
h1{
color:black;
text-align:center;
<!--font-family:cursi;-->
font: 400 15px/1.8 Lato, sans-serif;
letter-spacing:10px;
<!--letter-spacing: 5px;-->
font-size:20px;
}
input[type=text], input[type=password] {
width: 20%;
padding: 12px 20px;
margin: 8px 0;
display: inline-block;
border: 1px solid #ccc;
box-sizing: border-box;
}
button {
background-color: black;
color: white;
padding: 14px 20px;
margin: 8px 0;
border: none;
cursor: pointer;
width: 20%;
}
body{
text-align:center;
background-color:#fff;
color:#000000;
font: 400 15px/1.8 Lato, sans-serif;
letter-spacing: 5px;
font-size:20px;
}
button:hover {
opacity: 0.8;
}
.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}
img.avatar {
width: 40%;
border-radius: 50%;
}
.container {
padding: 16px;
}
span.psw {
float: right;
padding-top: 16px;
}
@media screen and (max-width: 300px) {
span.psw {
display: block;
float: none;
}
.cancelbtn {
width: 100%;
}
}
.container{
text-align:center;
}
</style>
</head>
<body>
<h1>BLOGGER REGISTRATION FORM</h1>
<form enctype="multipart/form-data" action="blogger_register.php" method="post">
Name: <input type="text" name="bname"><br/><br/>
Name of Blog: <input type="text" name="blogname"><br/><br/>
Contact no: <input type="text" name="bno" maxlength="12"><br/><br/>
Mail-id: <input type="email" name="bmail"><br/><br/>
Blog Type: <select name="blogtypes" placeholder="CHOOSE YOUR TYPE">
<option values="sports"> SPORTS BLOG </options>
<option values="food"> FOOD BLOG </options>
<option values="event"> EVENT BLOG </options>
<option values="arts"> ART BLOG </options>
<option values="fashion"> FASHION BLOG </options>
<option values="travel"> TRAVEL BLOG </options>
<option values="photo"> PHOTO BLOG </options>
<option values="book"> BOOK BLOG </options>
<option values="tech"> TECH BLOG </options>
<option values="music"> MUSIC BLOG </options>
<option values="movie"> MOVIE BLOG </options>
</select> <br/><br/>
Enter username: <input type="text" name="buser" ><br/><br/>
Enter password: <input type="password" name="bpass" ><br/><br/>
Re-enter password: <input type="password" name="bpass2" ><br/><br/>
Blogger ID Proof: <select name="prooftypes" placeholder="CHOOSE YOUR TYPE">
<option values="aacrd"> AADHAR CARD </options>
<option values="voter"> VOTER ID </options>
<option values="pan"> PAN CARD </options>
<option values="pass"> PASSPORT </options>
<option values="dlin"> DRIVING LICENSE </options>
</select> <br/><br/>
ID Proof Number : <input type="password" name="proofno" required><br/><br/>
Blog Link: <input type="text" name="link"><br/><br/>
*Bio should have a maximum of 140 characters<br>
Blogger's image:<input type="file" name="image"<br/><br/>
Bio: <textarea name ="text" rows=4 col=4 maxlength=140> </textarea required/ ><br/><br/>
<button class="button button1" name="submit">SUBMIT</button>
</form>
</body>
</html>
答案 0 :(得分:0)
我建议您使用文件上传脚本上传图片而不是手动编码。这家伙做了一个简洁易用的小脚本。 https://github.com/aivis/PHP-file-upload-class
就你的问题而言,我看到你实际上在哪里将图像写入任何目录。