我是mysqli / php世界的新手,我试图通过直接潜入练习来学习,但我在开始时陷入困境。
我做了一个简单的登录/传递表单,我想将数据存储到数据库,我不知道我在哪里犯了错误,但我一直没有得到任何数据。
你能指点我吗?
谢谢
登录 :
</tr>
<tr>
<td>
<label class="contact" >Password :</label></td>
<td>
<input class="input" type="password" name="Password" id="Password" /></td>
</tr>
<tr>
<td>
<input class="input" type="submit" value="submit" /></td>
</tr>
</table>
</form>require_once('co.php');
$username = "root";
$password = "";
$dbname = "test";
// Create connection
$conn = mysqli_connect("localhost", $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
class insert {
public function insert () {
if (isset($_POST['submit'] )){
$Login=$_POST['Login'];
$Password=$_POST['Password'];
$sql="INSERT INTO test (Login, Pass)VALUES ('$Login', '$Password')";}
mysqli_query($conn,$sql);
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}}
include('inscription.php');
?>
答案 0 :(得分:0)
试试这个:
<强> PHP 强>
<?php
if (isset($_POST['submit'], $_POST['Login'], $_POST['Password'] )){
$username = "root";
$password = "";
$dbname = "test";
$conn = mysqli_connect("localhost", $username, $password, $dbname);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$Login=mysqli_real_escape_string($_POST['Login'], $conn);
$Password=mysqli_real_escape_string($_POST['Password'], $conn);
$sql="INSERT INTO test (Login, Pass)VALUES ('$Login', '$Password')";
mysqli_query($conn,$sql);
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
}else{
echo 'missing fields '.var_dump($_POST);
}
?>
<强> FORM 强>
<form action ="" method="POST">
<table>
<tr>
<td>
<label for="login" class="contact" >Login :</label></td>
<td>
<input id="login" class="input" type="text" name="Login" id="Login" />
</td>
</tr>
<tr>
<td>
<label for="password" class="contact" >Password :</label></td>
<td>
<input id="password" class="input" type="password" name="Password" id="Password" />
</td>
</tr>
<tr>
<td>
<input class="input" type="submit" value="submit" name="submit"/>
</td>
</tr>
</table>
</form>
&#13;