我创建了包含文本字段和上传文件(register.php
)的表单,我想将数据发送到sendData.php
并重定向到payment.php
,以便用户为文档审核付款。我不知道sendData.php
出了什么问题,我尝试将数据从register.php
提交到sendData
并且输出为空白没有发现错误,我尝试检查mysql错误也没有发现错误。
页面包含表单数据
<?php
$errors = "";
if(isset($_GET["error"])){
if($_GET["error"] === "pwd"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> Passowrd dismatch, please try again</div>';
}
if($_GET["error"] === "undefined"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> File format dismatch, please try again</div>';
}
if($_GET["error"] === "found_file"){
$errors = '<div class="alert alert-danger col-md-3><span class="glyphicon glyphiocn-remove-circle"></span> Document found error, please try again</div>';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="../../favicon.ico">
<title>CentralAcademy: Register</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
<link href="css/bootstrap-theme.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link rel="stylesheet" href="css/jumbtron.css">
<link href="css/custom-file.css" rel="stylesheet">
<style type="text/css">
body{ padding-top: 80px; }
</style>
</head>
<body>
<?php require_once("includes/header.php"); ?>
<div class="container">
<div class="row">
<div class="col-lg-3 breadcrumb">
<h3 class="page-header">Payment</h3>
<p><img src="images/images.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)755-555-555</p><br>
<p><img src="images/airtelM.fw.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)685-555-555</p><br>
<p><img src="images/tigopesa.png" class="img img-responsive" width="70" height="50" style="display: block; float: left; padding-right:10px;"/> (+255)655-555-555</p><br>
</div>
<div class="col-lg-2"></div>
<div class="col-lg-7 breadcrumb">
<?php print $errors; ?>
<h3 class="page-header">Request for Document Review</h3>
<h5><font color="#FF0000">***</font> Please fill all fields required</h5><br>
<form action="sendData.php" method="post" enctype="multipart/form-data" class="form-horizontal">
<div class="form-group">
<div class="col-md-6">
<input name="fname" type="text" placeholder="Enter your FirstName" value="<?php echo isset($_POST['fname']) ? $_POST['fname'] : '' ?>" class="form-control" required id="fname">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="sname" type="text" class="form-control" value="<?php echo isset($_POST['sname']) ? $_POST['sname'] : '' ?>" placeholder="Enter your LastName" required id="sname">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="gender" type="radio" class="radio-inline" value="F" checked="CHECKED" required/>Female <input type="radio" name="gender" class="radio-inline" value="M" required/>Male</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="email" type="text" class="form-control" value="<?php echo isset($_POST['email']) ? $_POST['email'] : '' ?>" placeholder="Enter your Email Address" required id="email">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="phone" type="text" class="form-control" placeholder="Enter your Phone Number" value="<?php echo isset($_POST['phone']) ? $_POST['phone'] : '' ?>" maxlength="13" required id="phone" pattern="[\+]\d{3}\d{3}\d{6}">
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input type="radio" name="edlevel" value="bachelor" class="radio-inline" checked="CHECKED" required/>Bachelor
<input type="radio" name="edlevel" value="Post Graduate" class="radio-inline" />Post Grad
<input name="edlevel" type="radio" value="Masters" class="radio-inline" />Masters
<input name="edlevel" type="radio" value="PhD" class="radio-inline" />PhD
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="affi" type="text" class="form-control" value="<?php echo isset($_POST['affi']) ? $_POST['affi'] : '' ?>" placeholder="Enter organisation/College/University" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="title" type="text" class="form-control" value="<?php echo isset($_POST['title']) ? $_POST['title'] : '' ?>" placeholder="Enter your document title" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 fileUpload">
<input type="file" name="files" id="file"/>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="password" type="password" class="form-control" placeholder="Choose Your Password" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6">
<input name="password2" type="password" class="form-control" placeholder="Confirm Your Password" required>
</div>
</div>
<br>
<div class="form-group">
<div class="col-md-6">
<button name="Register" type="submit" class="btn btn-info"><span class="glyphicon glyphicon-user"></span> Register Now</button><br><br>
<p>If you are already registered please click<a href="login.php"> here</a></p>
</div>
</div>
</form>
</div>
</div>
</div>
<div class="container marketing">
<!-- START THE FEATURETTES -->
<?php require_once("includes/footer.php"); ?>
</div><!-- /.container -->
<script type="text/javascript" src="js/jquery-3.1.1.min.js"></script>
<script type="text/javascript" src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/main.js"></script>
</body>
</html>
//sendData.php
<?php
if(isset($_FILES['files']) && $_POST["password"] === $_POST["password2"]){
session_start();
require_once("includes/dbconnect.php");
$fname = $_POST["fname"];
$sname = $_POST["sname"];
$email = $_POST["email"];
$phone = $_POST["phone"];
$title = $_POST["title"];
$password = $_POST["password"];
$gender = $_POST["gender"];
$edlevel = $_POST["edlevel"];
$affi = $_POST["affi"];
//Keep all author data to session variable
$_SESSION["fname"] = $fname;
$_SESSION["sname"] = $sname;
$_SESSION["email"] = $email;
$_SESSION["phone"] = $email;
$_SESSION["passwprd"] = $password;
$_SESSION["gender"] = $gender;
$_SESSION["edlevel"] = $edlevel;
$_SESSION["affi"] = $affi;
$errors= array();
$extensions = array("docx");
$file_name = rand(1000,100000)."-".$_FILES['files']['name'];
$file_size = $_FILES['files']['size'];
$file_tmp = $_FILES['files']['tmp_name'];
$file_type = $_FILES['files']['type'];
$file_ext = strtolower(substr($_FILES['files']['name'],strrpos($_FILES['files']['name'],'.')+1));
if(in_array($file_ext,$extensions ) === true && $file_size < 2097152){
$result = $connect->query("INSERT INTO temp VALUES(NULL,'$title',$email','$file_name',now())");
if($result){
$desired_dir="AuthorReport";
if(empty($errors)===true){
if(is_dir($desired_dir)===false){
mkdir("$desired_dir", 0700); // Create directory if it does not exist
}
if(is_dir("$desired_dir/".$file_name)==false){
move_uploaded_file($file_tmp,"$desired_dir/".$file_name);
}else{ // rename the file if another one exist
$new_dir="$desired_dir/".$file_name.time();
rename($file_tmp,$new_dir) ;
}
header("location: payment.php");
exit();
}
else{ header("location:register.php?error=found_file"); exit(); }
}
}
else{ header("location:register.php?error=undefined"); exit(); }
}
else{ header("location:register.php?error=pwd"); exit(); }
?>
答案 0 :(得分:0)
$ email没有开始报价
$result = $connect->query("INSERT INTO temp VALUES(NULL,'$title',$email','$file_name',now())");
这就是你有错误的原因。
并确保在哪里准确输入这些值,并在INSERT语句中添加列名
$result = $connect->query("INSERT INTO temp
(column_title, column_email, column_filename, thedate)
VALUES
('$title','$email','$file_name',NOW() )" );