获取堆栈跟踪:#0 {main}使用PHP将HTML表单连接到SQL数据库时出错

时间:2017-07-06 02:03:03

标签: php mysql xampp

您好我使用的是一个简单的html表单,点击提交按钮后,表单数据应存储在SQl数据库中。我正在使用PHP 7的Xamp服务器。

Html代码:

<html>
<head>
</head>
<body>
<p><h1>Student Information Input Form</h1></p>
<section>
<form method="post" action="connection.php">
<p><b>Name:</b>&nbsp;<input type="text" id="name"></input></p>
<p><b>Username:</b>&nbsp;<input type="text" id="username"></input></p>
<p><b>Password:</b>&nbsp;<input type="password" id="password"></input></p>
<p><b>Email:</b>&nbsp;<input type="email" id="email"></input></p>
<p><input type="submit" id="submit"></p>
</form>
</section>
</body>
</html> 

PHP代码:

<?php
$servername='localhost';
$username='root';
$password='';
$dbname='newdb';

//Create Connection
$conn=new sqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

//get values from form
$name=$_POST['name'];
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];


//Insert Values
$sql = "INSERT INTO userinfo (name, username, password, email)
VALUES ('$name', '$username', '$password', 'email')";

//To check whether data is inserted properly or not
if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
} else {
    echo "Error: " . $sql . "<br>" . $conn->error;
}

$conn->close();
?>

错误讯息:

Fatal error: Uncaught Error: Class 'sqli' not found in     
C:\xampp\htdocs\Project2_php db\connection.php:8 Stack trace: #0 
{main} thrown in C:\xampp\htdocs\Project2_php db\connection.php on line 8

0 个答案:

没有答案