【发布时间】:2014-04-14 08:58:57
【问题描述】:
我正在尝试将数据插入数据库 mysql phpAdmin。
我的虚拟主机是 000webhost。
我连接mysql数据库代码:
<?PHP
$mysql_host = "mysql2.000webhost.com";
$mysql_database = "*********";
$mysql_user = "********";
$mysql_password = "**********";
$dbcon = mysql_connect($mysql_host,$mysql_user,$mysql_password,$mysql_database);
if (!$dbcon) {
die('error connecting to database');
}
echo ('You have connected successfully');
?>
我的插入数据代码:
<?PHP
if (isset($_POST['submitted'])) {
include('connect_mysql.php');
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$sqlinsert = "INSERT INTO people (firstname, lastname) VALUES ('$fname', '$lname')";
if (!mysql_query($dbcon, $sqlinsert)) {
die('error inserting new record');
} // end of nested if statement
$newrecord = "1 record added to the database";
}
?>
<html>
<head>
<title>Insert Data into DB</title>
</head>
<body>
<h1>Insert Data into DB</h1>
<form method="post" action="insert-data.php">
<input type="hidden" name="submitted" value="true" />
<fieldset>
<legend>New People</legend>
<label>First Name: <input type="text" name="fname" /></label>
<label>Last Name: <input type="text" name="lname" /></label>
</fieldset>
<br />
<input type="submit" value="add new person" />
</form>
<?PHP
echo $newrecord
?>
</body>
</html>
它没有让我把它放到数据库中,而是把我带到了这个页面 http://error404.000webhost.com/?
【问题讨论】:
-
您在查询中的变量名前没有
$符号 -
你正在混合 mysqli_ 和 mysql 先修复它!!
-
看我的回答来检查
标签: php html mysql phpmyadmin