-6

「顧客」が情報を追加できるようにする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.");
  ?>

4

1 に答える 1