【发布时间】:2015-11-01 02:50:17
【问题描述】:
我已经坚持了 3 天了,非常感谢任何帮助。 请注意,我现在将 php 和 html 放在一个页面中,直到我让它工作,然后一旦它被修复,我会将 php 连接脚本放入其通常的文件夹中。 当我进入注册页面时,我可以看到我已连接到我的并且我可以填写我的表格并提交它而没有任何错误,但是数据库不会更新,并且当我刷新数据库时没有找到新用户。 以下是我到目前为止的代码,如果有人能告诉我我做错了什么或者我可以改进以解决这个错误,我将非常感激。 提前谢谢!
<?php
$host="localhost";
$dbuser="root";
$pass="********";
$dbname="amsadler";
$con = mysqli_connect ($host, $dbuser, $pass, $dbname);
if (mysqli_connect_errno ())
{
die ("Connection Failed!" . mysqli_connect_error());
}
else
{
echo "Connected to database {$dbname} ";
}
if(isset($_POST['submit']))
{
$fname = mysqli_real_escape_string($con, $_POST ['fname']);
$lname= mysqli_real_escape_string($con, $_POST ['lname']);
$email= mysqli_real_escape_string($con, $_POST ['email']);
$pswrd= mysqli_real_escape_string($con, $_POST ['pswrd']);
$sql = $con->query("INSERT INTO users ( fname, lname, email, pswrd,)
VALUES ( ' {$fname} ' , ' {$lname} ' , ' {$email} ' , ' {$pswrd} ' )");
}
?>
<!DOCTYPE html>
<html lang="en-US">
<head>
<title>Signup</title>
<meta charset="utf-8">
<meta name="description" content="description of webpage">
<meta name="keywords" content="keywords go here">
<meta name="author" content="amsadler">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/signup.css">
<link rel="index" href="index.php">
<link rel="icon" href="img/favicon.png" sizes="16x16" type="image/png">
</head>
<body>
<div class="header">
<div id="logo">
<a href="index.php"><img src="img/logo.png" alt="logo" title="blah blah"/></a>
</div>
</div>
<div id="signupform">
<form method="post"><br>
<input type="text" id="fname" name="fname" placeholder="First name">
<input type="text" id="lname" name="lname" placeholder="Last name"><br><br>
<input type="text" id="email" name="email" placeholder="Email address">
<input type="password" id="pswrd" name="pswrd" placeholder="Password"><br><br>
<input id="button" type="submit" value="Submit">
</form>
</div>
<?php
include ("inc/footer.php");
?>
</body>
</html>
【问题讨论】: