【发布时间】:2016-05-15 06:29:17
【问题描述】:
这是我的数据库连接文件。 (db_configenter code here.php)
<?php
$con = mysqli_connect("localhost","root","","oop");
if(mysqli_connect_errno())
{
echo "failed to connect to mysql:" . mysqli_connect_error();
}
?>
这是我的 user.class.php 代码
<?php
include "db_config.php";
class User
{
public function registration($fname,$lname,$username,$email,$password)
{
$sql = $con->query("INSERT INTO users_registration(fname,lname,username,email,password)
VALUES('$fname','$lname','$username','$email','$password',)");
return $sql;
}
}
?>
最后我的registrtaion.php文件在这里
<?php
include "class.user.php";
$user = new User();
if (isset($_POST['submit']))
{
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
$user->registration($fname,$lname,$username,$email,$password);
echo "registration success";
}
?>
<!DOCTYPE HTML>
<html>
<head>
<title>Registration Form</title>
<link rel="stylesheet" href="css/style.css" type="text/css">
</head>
<body>
<div class="wrapper"><!--wrapper start here-->
<form action="" method="POST">
<input type="text" name="fname" placeholder="First name"/><br>
<input type="text" name="lname" placeholder="Lastst name"/><br>
<input type="text" name="username" placeholder="User name"/><br>
<input type="text" name="email" placeholder="Email id"/><br>
<input type="text" name="password" placeholder="Password"/><br>
<input type="text" name="cpassword" placeholder="Confirm Password"/><br>
<input type="button" value="submit" name="submit" class="btn"/>
</form>
</div><!--wrapper ends here-->
</body>
</html>
我无法将数据插入数据库,当我提交按钮时什么也没发生。请帮我解决问题。我是 php 新手。 还想在同一字段中添加图像。 提前致谢。
【问题讨论】: