我试图添加一个字段到我的数据库,但每次我点击插入我得到错误“对象未找到”这里是我的游戏\输入\形式.php
<html><head><title>Games Insert Form</title>
<style type="text/css">
td {font-family: tahoma, arial, verdana; font-size: 10pt }
</style>
</head>
<body>
<table width="300" cellpadding="5" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="left" colspan="1" rowspan="1" bgcolor="64b1ff">
<h3>Insert Game</h3>
<form method="GET" action="enter_details.php">
Enter Game ID: <input type=text name=gameid size=30><br>
Enter Name: <input type=text name=name size=30><br>
Enter Platform: <input type=text name=platform size=30><br>
Enter Price :<br> <input type=text name=price size=20><br>
<br>
<input type=submit value=Insert><input type=reset>
</form>
</td></tr></table>
</body>
</html>
mygametest.php(我在这个文件中找不到任何错误,看起来很好)
<?php
$host="localhost";
$user="root";
$password="";
$con=mysqli_connect($host,$user,$password) or die(mysql_error());
echo "Connected to MySQL<br/>";
mysqli_select_db($con,"gamedb") or die(mysqli_error());
echo "Connected to Database";
// Create a MySQL table in the selected database
$query=mysqli_query($con,"CREATE TABLE gameinfo(
id INT NOT NULL AUTO_INCREMENT,
PRIMARY KEY(id),
name VARCHAR(30),
platform VARCHAR(30),
price DECIMAL)")
or die(mysqli_error());
echo "Table Created!";
?>
这是我的游戏显示记录
<html>
<head><title>Display Records</title>
<style type="text/css">
th, td {font-family: tahoma, arial, verdana; font-size: 10pt; font-weight: 500 }
</style>
</head>
<body>
<?php
$db="gamedb";
$link = mysqli_connect('localhost', 'root', '',$db);
if (mysqli_connect_errno()) {
trigger_error('Database connection failed: ' . mysqli_connect_error(), E_USER_ERROR);
}
$result = mysqli_query($link, "SELECT * FROM gameinfo" ) or die("SELECT Error: ".mysqli_error($link));
$num_rows = mysqli_num_rows($result);
print "There are $num_rows records.<br><br>";
/* Display a html table */
print "<table width=600 border=1>";
print "<tr><th>ID</th><th>Name</th><th>Platform</th><th>Price</th></tr>";
/* Outer loop using mysqli fetch row function to extract a single record and store it in php variable $get_info */
while ($get_info = mysqli_fetch_row($result)){
print "<tr>";
/* Inner foreach loop to extract a single field from $get_info and store it in php variable $field */
foreach ($get_info as $field)
print "<td>$field</td>"; //display the field as a table cell
print "</tr>";
}
print "</table>";
mysqli_close($link);
?>
<br>
<form method="POST" action="mainForm.php">
<input type="submit" value="Database Interface">
</form>
</body>
</html>
这是我的enter\u details.php
<html><head><title>Student Insert Record</title></head>
<body>
<?php
$gameNum=$_GET['gameid'];
$name =$_GET['name'];
$platform=$_GET['platform'];
$price=$_GET['price'];
$db="gamedb";
$db = new mysqli('localhost', 'root', '', 'gamedb');
if($db->connect_errno > 0){
die('Error : ('. $db->connect_errno .') '. $db->connect_error);
}
$result=mysqli_query($db,"INSERT INTO gameinfo (gameid, name, platform, price)
VALUES ('$gameNum', '$name', '$platform', '$price')") or die("Insert Error: ".mysqli_error($link));
mysqli_close($db); // Close the connection to the mysql server
print "Record added";
?>
<form method="POST" action="game_input_form.php">
<input type="submit" value="Insert Another game Record">
</form>
<br>
<form method="POST" action="mainForm.php">
<input type="submit" value="Back to Student Records System Menu">
</form>
</body>
</html>
我已经浏览了每一页,只是似乎找不到错误,我真的不知道我哪里出错了,当我在浏览器中进入myphpadmin时,我可以看到带有记录的表格,但除此之外,我丢失了,任何帮助将不胜感激?抱歉发了这么长的邮件
1条答案
按热度按时间waxmsbnn1#
在您输入的\u details.php中有insert语句。
但不应该是吗
根据gametest.php,您正在创建一个具有列名id的表,并且正在向列名gameid插入值。
希望这能解决问题。:)