gpt4 book ai didi

php - 连接 Php、html 和 mysql

转载 作者:行者123 更新时间:2023-11-29 09:10:32 25 4
gpt4 key购买 nike

有人可以查看我的代码并让我知道它出了什么问题吗?

我遇到的问题是,当我在 3 个字段中输入文本并点击提交时,它不会插入到我的数据库(mysql,使用 phpmyadmin 作为 gui)。没有错误消息或任何东西;它根本不插入数据..

我一遍又一遍地查看代码,但无法指出它的问题所在。

//---------------------------This is my index.php------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Web Bar Title</title>
<link rel="stylesheet" href="styles.css" type="text/css" />
</head>
<body>


<?php
if(isset($_POST['Submit']))
{
include 'connectdb.php';
include 'openconnection.php';

$first = $_POST['first'];
$second = $_POST['second'];
$third = $_POST['third'];

$query = "INSERT INTO details (first, last, third) VALUES('$first','$second','$third');";
mysql_query($query) or die('Error, insert query failed');
}
?>

<div id="page">

<tbody>
<form method="post">
<table>
<tr>
<td ><b>First</b></td>
<td><input name="first" type="text" id="first"></td>
<tr>
<tr>
<td ><b>Second</b></td>
<td><input name="second" type="text" id="second"></td>
<tr>
<td ><b>Company</b></td>
<td><input name="third" type="text" id="third" > </td>
</tr>
</table>
<input name="submit" type="submit" id="submit" value="Submit" />
</form>
</body>
</html>
</tbody>

</div>

//---------------------------------connectdb.php------------------------------------------
<?php
$dbhost = 'localhost';
$dbuser = 'sharkk';
$dbpass = 'pw';
$dbname = 'test';
?>

//---------------------------------openconnection.php-------------------------------------
<?php
$dbhost = 'localhost';
$dbuser = 'sharkk';
$dbpass = 'pw';
$dbname = 'test';
?>

<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname) or die ('No Selection of Database');
?>

编辑:通过 MSN/AIM/Steam/Skype 进行交流会更容易、更快捷,如果有人有的话!

最佳答案

将顶行更改为

if( isset( $_POST['submit'] ) ) {

我不记得是否区分大小写

关于php - 连接 Php、html 和 mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5699824/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com