我正在尝试创建一个 php 文件,该文件将允许“客户”向其中添加信息,并且在添加和提交该信息时,应将信息添加到我的数据库中。但是,经过几次尝试,我无法将数据输入数据库。
这是用户能够查看表单的代码...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Payment</title>
<link rel="stylesheet" type="text/css" href="styleshoppingcart.css"/>
</head>
<body>
<p>Please Enter The Following Details</p>
<form method="post" action="outputty.php">
<p>
<label>Name:<input name="name" type="text"/></label>
</p>
<p>
<label>Last Name:<input name="lastname" type="text"/></label>
</p>
<p>
<label>Card Type:<input name="cardtype" type="text"/></label>
</p>
<p>
<label>Card Number:<input name="cardnumber" type="text"/></label>
</p>
<p>
<label>Expiry Date:<input name="expiry" type="text"/></label>
</p>
<p>
<label>Door Number Date:<input name="doornumber" type="text"/></label>
</p>
<p>
<label>Post Code:<input name="postcode" type="text"/></label>
</p>
<p>
<input type="submit" value="Submit Form"/>
<input type="reset" value="Clear Entries"/>
</p>
</form>
</body>
</html>
这是 PHP 文件的代码,它应该允许将数据输入到数据库中。
<?xml version=\"1.0\" encoding=\"utf-8\"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>NBA Memorabilia | Orders</title>
<link rel="stylesheet" type="text/css" href="styleshoppingcart.css"/>
</head>
<body>
<h2>Orders</h2>
<?php
//Connect to database
$location = "localhost";
$username = "********";
$password = "********";
$database = "db?k1009076";
$conn=@mysql_connect("$location","$username","$password");
if (!$conn) die ("Error: Could not connect to database server.");
@mysql_select_db($database,$conn) or die ("Error: Could not open database.");
extract($_POST);
if (isset($name))
{
//Add new comment to database
@mysql_query("CREATE TABLE order (name VARCHAR(65),lastname VARCHAR(65),
cardtype VARCHAR(8), cardnumber VARCHAR(16), expiryVARCHAR(4),doornumber VARCHAR(10), postcode VARCHAR(10) )");
$insert = "INSERT INTO order (name,lastname, cardtype, cardnumber, expiry, doornumber, postcode)
VALUES ('$name','$lastname','$cardtype', '$cardnumber', '$expiry','$doornumber','$postcode')";
@mysql_query($insert) or die ("Could not add data to the table");
}
//Close connection to server
@$disconn=mysql_close($conn);
if (!$disconn) die ("Error: Unable to disconnect from database server.");
?>