我試圖創建一個PHP文件,該文件將允許「客戶」信息添加到當這些信息被添加和提交,信息應該被添加到我的數據庫中。但是,經過多次嘗試,我無法將數據輸入到數據庫中。創建一個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";
[email protected]_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.");
?>
不這樣做,它從來就不是一個好主意,卡號和支付信息存儲在自己的數據庫。尤其是隨着你寫的代碼。它容易受到各種攻擊。 – 2013-03-21 16:06:39
另外,在發佈代碼時,不要留下您的MySQL連接詳細信息,例如用戶名和密碼。 – 2013-03-21 16:06:50
發佈Apache的錯誤日誌。它會告訴你錯誤在哪裏。 – JorgeeFG 2013-03-21 16:07:30