在您提出任何问题之前,我会在8周内搜索答案, 我的问题是: 我正在建立一个论坛,只是一个业余项目, 并且我已经设置了所有内容,用户,主题,回复,单身,电子邮件确认等。
在我的注册脚本中,我想检查用户是否选择了图像。 如果他这样做,则将图像作为Blob文件上传。我做到了,而且效果很好。 但是,如果用户在注册时没有选择图像,则当他查看自己的个人资料或创建线索时,基本上是在他显示自己的个人资料图像时,其显示的是“无此类文件”图像。我希望在发送查询以添加用户之前,先检查他是否选择了图像,否则,请选择名为“ images / default.jpg”的文件并上传。
这是我当前的注册文件:
register.php
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<title>Forum Test</title>
<link rel="stylesheet" type="text/css" href="style/registerstyle.css">
</head>
<body>
<h2>Coder'sCrux's Forum</h2>
<center><form action='register_parse.php' enctype='multipart/form-data' method='post'>
<p>Username:</p> <center><input type='text' name='username' required/></center><br />
<p>Password:</p> <center><input type='password' name='password' required/></center><br />
<p>Re-enter Password:</p> <center><input type='password' name='password2' required/></center><br />
<p>Email:</p> <center><input type='text' name='email' required/></center><br />
<button type='submit'>Sign Up</button>
</form></center>
</body>
</html>
register_parse.php
<?php
session_start();
//error_reporting(!8);
//error_reporting(!2);
include_once("connect.php");
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
if ($username && $password && $password2 && $email) {
if ($password == $password2) {
$query = "SELECT * FROM users WHERE username='".$username."' OR email='".$email."' LIMIT 1";
$result = mysqli_query($connection, $query);
if (mysqli_fetch_row($result)) {
echo "Username or Email taken. If you already have an account, connect to it instead.";
} else {
$confirmcode = rand();
$query2 = "INSERT INTO users (username, password, email, confirmed, confirm_code) VALUES ('".$username."', '".$password."', '".$email."', '0', '".$confirmcode."')";
$result2 = mysqli_query($connection, $query2) or die(mysqli_error($connection));
$message = "
Confirm Your email
Click the link below to verify your account
http://coderscrux.ddns.net/forum/confirm.php?username=".$username."&code=".$confirmcode
;
if ($result2) {
mail($email, "Coder'sCrux Email Confirmation", $message, "From: coderscrux#gmail.com");
echo "Registration Complete! Please confirm your email to unlock all features, or go back to the <a href='index.php'>main website</a>.";
}
}
} else {
echo "Your passwords do not match.";
}
}
?>
谢谢!