我试图写一个注册表,首先我试着做OO,但这没有回应,似乎只是清除表格并刷新页面,但没有插入任何数据:
编辑:当前代码:
<?php
session_start();
include 'registrationform.php';
include 'connection.php';
if (isset($_POST['regsubmit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$user = $_POST['username'];
$pass = $_POST['password'];
$query = "INSERT INTO users (firstname, lastname, username, password) VALUES(?, ?, ?, ?)";
$statement = $connection->prepare($query);
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('ssss', $firstname, $lastname, $username, $password);
if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />';
//$_SESSION['username'] = $_POST['username'];
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();
?>
注册表
<!DOCTYPE html>
<?php
include 'header.php';
?>
<center>
<html>
<link rel="stylesheet" type="text/css" href="web.css" />
</font>
<head>
</head>
<body>
<div id="registrationform">
Please enter your registration details<br /><br />
<form method="post" action="registrationsubmit.php">
First Name:
<input type="text" name="firstname" />
<br /><br>
Last Name:
<input type="text" name="lastname" />
<br /><br>
Username:
<input type="text" name="username" />
<br /><br>
Password:
<input type="text" name="password" />
<br /><br>
<input type="submit" name="regsubmit" value="Submit" />
</form>
</div>
</body>
</html>
</center>
OO尝试
<?php
session_start();
include 'registrationform.php';
include 'connection.php';
if (isset($_POST['regsubmit']))
{
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$user = $_POST['username'];
$pass = $_POST['password'];
$stmt = $connection->prepare("INSERT INTO users VALUES (?, ?, ?, ?)");
$stmt->bind_param('ssss', $firstname, $lastname, $user, $pass);
$stmt->execute();
printf("%d Row inserted.\n", $stmt->affected_rows);
$stmt->close();
}
?>
由于这不起作用,我尝试在没有OO的情况下进行操作,作为起点。但是现在我给出了错误&#34;访问被拒绝用户&#39;&#39; 10.246.64.24&#39; (使用密码:否)&#34;,但我的连接很好,我也写了一个完美的登录,所以无法解决。这是我目前的代码:
registrationsubmit.php
<?php
include "connection.php";
include "header.php";
if(isset($_POST['regsubmit']))
{
mysql_select_db("c3438525_co_uk",$connection);
$firstname = $_POST['$firstname'];
$lastname = $_POST['$lastname'];
$username = $_POST['username'];
$password = $_POST['password'];
$query = "INSERT INTO users (FirstName, LastName, Username, Password) VALUES ('$firstname', '$lastname', '$username', '$password')";
$data = mysql_query ($query)or die(mysql_error());
if($data) { echo "Successfully Registered"; }
else
{
?>
<script>alert('error while registering you...');</script>
<?php
}
}
?>
Connection.php
<?php
ob_start();
$connection = mysqli_connect("***", "***", "BFUWGpn3", "***");
?>
答案 0 :(得分:2)
你正在使用mysqli_连接,你的查询是mysql _
对于registrationsubmit.php
在线上使用一些东西:
$query = "INSERT INTO users (firstname, lastname, username, password) VALUES(?, ?, ?, ?)";
$statement = $connection->prepare($query);
//bind parameters for markers, where (s = string, i = integer, d = double, b = blob)
$statement->bind_param('ssss', $firstname, $lastname, $username, $password);
if($statement->execute()){
print 'Success! ID of last inserted record is : ' .$statement->insert_id .'<br />';
//$_SESSION['username'] = $_POST['username'];
}else{
die('Error : ('. $mysqli->errno .') '. $mysqli->error);
}
$statement->close();