我在php写的很久了,我现在正在尝试做一个简单的插入,但是它没有工作且没有显示错误,看到一些先前有关此问题的投诉但是他们的解决方案没有帮助我,该表包含此列user_ID的,用户名,密码,权限。代码如下。
<?php
include('connect.php');
//Start session
session_start();
?>
<div id="wrapper">
<!-- Navigation -->
<?php include('header.php'); ?>
<div id="page-wrapper">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">Create User</h1>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
<div class="row">
<div class="col-lg-12">
<div class="panel panel-primary">
<div class="panel-heading">
Fill in all details
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-12">
<form role="form">
<div class="col-lg-4">
<div class="form-group">
<input class="form-control" name="usernamei" id="inputUsername" placeholder="Username">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<input class="form-control" name="passwordi" id="inputPassword" placeholder="Password">
</div>
</div>
<div class="col-lg-4">
<div class="form-group">
<select class="form-control" name="permissioni" id="inputPermission">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</select>
</div>
</div>
<button type="submit" class="btn btn-primary">Submit Button</button>
<button type="reset" class="btn btn-primary">Reset Button</button>
</form>
</div>
</div>
<!-- /.row (nested) -->
</div>
<!-- /.panel-body -->
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
<!-- /#page-wrapper -->
</div>
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$myusername = mysqli_real_escape_string($conn,$_POST['usernamei']);
$mypassword = mysqli_real_escape_string($conn,$_POST['passwordi']);
$mypermission = mysqli_real_escape_string($conn,$_POST['permissioni']);
$sql = "INSERT INTO user(username, password, permission)
VALUES('$myusername', '$mypassword', '$mypermission')";
$r = mysqli_query ($conn, $sql);
if ($r) {
echo "success";
}else{
echo mysqli_error($conn);
}
mysqli_close($conn);
}
&GT;
答案 0 :(得分:0)
我可以向你保证它会产生错误。它只是没有显示它。为了让它显示错误,您必须按照以下步骤操作。
1)打开你的php.ini文件
2)找到标记为
的行display_errors = Off
3)将行改为
display_errors = On
4)保存文件
5)重启服务器
然后会显示错误,这将使处理情况变得更加容易。如果您在生产服务器上,请记住在完成问题解决后关闭显示错误。