无法通过html和php表单将数据插入mysql数据库

qv7cva1a  于 2021-06-17  发布在  Mysql
关注(0)|答案(1)|浏览(389)

这个问题在这里已经有答案了

我可以在php中混合mysql api吗(4个答案)
引用-这个错误在php中是什么意思(36个答案)
如何启用php短标记(19个答案)
两年前关门了。
我无法成功地将信息插入到我创建的数据库中。我在网上找到了几种不同的选择,希望有人能帮我。据我所知,我连接到数据库没有任何问题,数据只是没有提交到它。我保持它非常简单只是为了测试的目的,但没有用。这很可能是一个更有经验的程序员可以很容易帮助的简单的事情。
我正在通过a2hosting运行一个服务器,该服务器运行“server version:10.2.18-mariadb-cll-lve-mariadb server”“php version:5.6.30”
下面是我运行的代码(出于安全考虑,我在info中被替换):我对数据库表和字段名、用户名和字母大小写也进行了“虚拟检查”。
config.php文件:

<?php
$host = "server.a2hosting.com";
$userName = "username";
$password = "password";
$dbName = "Database";

// Create database connection
$conn = mysql_connect ($host, $userName, $password, $dbName);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
?>

html文件-index.html:

<html><body> <form method="post" action="index.php"> <input type='text' name='first_name' id='first_name'> <input type='text’ name='last_name'> <input type=submit value="Submit"> </form>
 </body></html>

php文件-index.php

<?  include("config.php"); 
// has the access info for the DB, how to connect

 // create a variable
$first_name=$_POST['first_name'];
$last_name=$_POST['last_name'];

 $query = "INSERT INTO Contact_Information (HOW_name, address) VALUES
 ('$first_name', '$last_name'); "; mysql_query($query); mysql_close();

 ?>

 <html> <head> <meta HTTP-EQUIV="REFRESH" content="0; url=form1.php">
 </head> </html>
7kjnsjlb

7kjnsjlb1#

$query=“插入联系人信息(how_name,address)值('$first_name','$last_name');”;
$result=mysqli\u query($conn,$query);
查询和结果应该是这样的。

相关问题