【发布时间】:2019-06-20 00:27:39
【问题描述】:
我已经尝试了几个小时无济于事,我的代码告诉我我已经成功连接,但是当我点击注册时页面刚刚刷新,我检查我的数据库没有任何变化,我尝试了几个不同的在线脚本可能检查它是否是我的代码,没有工作,我更新了我的 Godaddy SQL 版本,仍然没有改变..?
我希望有人能告诉我我做错了什么,谢谢,这是我正在使用的代码。
<!DOCTYPE html>
<?php
$servername = "localhost";
$username="****";
$password="*****";
$dbname="****";
try{
$conn = mysqli_connect($servername, $username,$password,$dbname);
echo("successful in connection");
}catch(MySQLi_Sql_Exception $ex){
echo("error in connection");
}
if(isset($_POST['submit'])){
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];
$register_query = "INSERT INTO `users`('email`, `username`, `password`) VALUES ('$email','$username','$password')";
try{
$register_result = mysqli_query($conn, $register_query);
if($register_result){
if(mysqli_affected_rows($conn)>0){
echo("registration successful");
}else{
echo("error in registration");
}
}
}catch(Exception $ex){
echo("error".$ex->getMessage());
}
}
?>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title>Register</title>
<link rel='stylesheet' href='http://netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css'>
<link rel="stylesheet" href="css/style.css">
</head>
<body id="fullBg">
<div class="container">
<form class="form-signin" id="login-register" method="post" action="">
<h1 class="form-signin-heading">Join The Club</h1>
<div style="margin:auto; width:135px; height:135px; background-color:grey; margin-bottom:15px; border-radius:50%;">
<br>
</div>
<input style="" type="text" class="form-control" name="username" value="<?php echo $username; ?>" placeholder="Username" />
<input type="text" class="form-control" name="email" id="inputEmail" placeholder="Email" />
<input style="margin:0px; margin-bottom:15px;" type="password" class="form-control" name="password" id="inputPassword" placeholder="Password" />
<input type="text" class="form-control" name="ppemail" value="<?php echo $ppemail; ?>" placeholder="Paypal Email"/>
<br>
<button class="logo-button btn-block" type="submit">Register</button>
</form>
<a href="/login.php"><p class="text-center sign-up" style="color:black !important;">Back To <strong>Login</strong></p></a>
<?php if(isset($smsg)){ ?><div class="alert alert-success" role="alert"> <?php echo $smsg; ?> </div><?php } ?>
</div>
</body>
</html>
【问题讨论】:
-
请注意,您直接将用户给定的值放入 SQL 字符串。这使您容易受到 SQL 注入的影响,并且如果有人碰巧在数据中添加了“,则很容易破坏一切。使用参数/准备好的语句。
-
我知道,但问题是它甚至不会发布到 mySQL,所以不会有任何危险 xD
-
所以你知道错了,还是去做,然后想知道为什么会出现问题?似乎不合逻辑