【发布时间】:2014-05-24 18:57:11
【问题描述】:
我的问题:isset() 不工作我在数据库中得到空白行!空()不起作用! 我试图将html页面放入,但无法正常工作!谢谢! 我的问题:isset() 不工作我在数据库中得到空白行!空()不起作用! 我试图将html页面放入,但无法正常工作!谢谢!
<?php
include_once 'include/db_connect.php';
include_once 'include/functions.php';
if($_POST) {
newMember($mysqli);
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Add user</title>
</head>
<body>
<h1 class="text-center">Add User</h1>
<link class="cssdeck" rel="stylesheet" href="media/css/bootstrap.min.css">
<link class="cssdeck" rel="stylesheet" href="media/css/bootstrap-select.css">
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/2.3.1/css/bootstrap-responsive.min.css" class="cssdeck">
<div class="modal-body">
<form id="tab" action="adduser.php" method="post">
<label>Username</label>
<input type="text" name="username" class="input-xlarge">
<label>Full Name</label>
<input type="text" name="fullname" class="input-xlarge">
<label>Email</label>
<input type="text" name="email" class="input-xlarge">
<label>Password</label>
<input type="password" name="password" class="input-xlarge"><br>
<div>
<label>Role:</label>
<select name="role" class="selectpicker" style="width:87%">
<option value="admin">Admin</option>
<option value="pm">Project Manager</option>
<option value="php">PHP Programmer</option>
<option value="seo">SEO Programmer</option>
<option value="webdesign">Web Designer</option>
</select>
</div>
<div class="text-center" style="padding-top:20px">
<button class="btn btn-primary">Create Account</button>
</div>
</form>
</div>
这是functions.php中的函数
function newMember($mysqli)
{ if(isset($_POST['fullname'],$_POST['username'],$_POST['password'],$_POST['email']))
{
$fullname = $_POST['fullname'];
$username = $_POST['username'];
$password = $_POST['password'];
$password = md5($password);
$email = $_POST['email'];
$role = $_POST['role'];
$statement = $mysqli->query("INSERT into members(fullname,username,password,email,role) VALUES ('$fullname','$username','$password','$email','$role')");
if($statement)
{
echo '<p class="alert alert-success text-center">User added.</p>';
}
} else {
echo 'Complete all boxes.';
}
}
【问题讨论】:
-
变量可以设置但为空!
-
您应该很高兴您没有因为将未转义的字符串插入 SQL 查询而变得更糟!谢谢!
-
如何解决问题?我只想确保在设置 htmlentities 后不添加空输入
-
使用
mysqli_real_escape_string($connect, strip_tags($_POST['..'])); -
那么isset或empty的范围是什么?