0

単純なデータベースを作成していますが、なぜ機能しないのかわかりません。[送信] ボタンをクリックしても、テーブルが作成されず、データベースにデータが保存されません。

エラーレポートが表示されないため、何が問題なのかわかりません。

これが私のコードです。

<?php // CONTROLLED PAGE
require_once('pdsACcontrolled.php'); //includes my DB connection

$surnamex = $_POST["surname"];
$firstnamex = $_POST["firstname"];
$middlenamex = $_POST["middlename"];
$nameextensionx = $_POST["nameextension"];
$bdatex = $_POST["bdate"];
$bplacex = $_POST["bplace"];
$sexx = $_POST["sex"];
$civstatx = $_POST["civstat"];
$citizenshipx = $_POST["citizenship"];
$heightx = $_POST["height"];
$weightx = $_POST["weight"];
$bloodtypetx = $_POST["bloodtype"];
$gsisnox = $_POST["gsisno"];
$pagibignox = $_POST["pagibigno"];
$philhealthnox = $_POST["philhealthno"];
$sssx = $_POST["sssno"];
$resaddx = $_POST["resadd"];
$zipcodex = $_POST["zipcode"];
$telnox = $_POST["telno"];
$emailaddx = $_POST["emailadd"];
$cellnox = $_POST["cellno"];
$agencynox = $_POST["agencyno"];
$tin = $_POST["tin"];


$uid = mysql_real_escape_string($uid);

if($_POST['submitbutton'] == "submit")
{

$sql = "CREATE TABLE $uid
        ( _key INT NOT NULL AUTO_INCREMENT
        , surname  TEXT(50) NOT NULL DEFAULT '?'
        , firstname  TEXT(50) NOT NULL DEFAULT '?'
        , middlename  TEXT(50) NOT NULL DEFAULT '?'
        , nameextension  TEXT(50) NOT NULL DEFAULT '?'
        , bdate  DATE NOT NULL DEFAULT '?'
        , bplace  TEXT(200) NOT NULL DEFAULT '?'
        , sex  TEXT NOT NULL DEFAULT '?'
        , civstat  TEXT NOT NULL DEFAULT '?'
        , citizenship  TEXT(50) NOT NULL DEFAULT '?'
        , height  INT(10) NOT NULL DEFAULT '?'
        , weight  INT(10) NOT NULL DEFAULT '?'
        , bloodtype  TEXT(50) NOT NULL DEFAULT '?'
        , gsisno  TEXT(50) NOT NULL DEFAULT '?'
        , pagibigno  TEXT(50) NOT NULL DEFAULT '?'
        , philhealthno  TEXT(50) NOT NULL DEFAULT '?'
        , sssno  TEXT(50) NOT NULL DEFAULT '?'
        , resadd  TEXT(500) NOT NULL DEFAULT '?'
        , zipcode  TEXT(50) NOT NULL DEFAULT '?'
        , telno  INT(20) NOT NULL DEFAULT '?'
        , emailadd  TEXT(50) NOT NULL DEFAULT '?'
        , cellno  int(20) NOT NULL DEFAULT '?'
        , agencyno  TEXT(50) NOT NULL DEFAULT '?'
        , tin  TEXT(50) NOT NULL DEFAULT '?'
        , PRIMARY KEY (_key))";




        $query="INSERT INTO $uid(surname,firstname,middlename,nameextension,bdate,bplace,sex,civstat,citizenship,height,weight,bloodtype,gsisno,pagibigno,philhealthno,sssno,resadd,zipcode,telno,emailadd,cellno,agencyno,tin)VALUES('$surnamex','$firstnamex','$nameextensionx','$bdatex','$bplacex','$sexx','$civstatx','$citizenshipx','$heightx','$weightx','$bloodtypex','$gsisnox','$pagibignox','$philhealthnox','$sssnox','$resaddx','$zipcodex','$telnox','$emailaddx','$cellnox','$agencynox','$tinx')";

        mysql_query($query) or die (mysql_error());
        echo "The user $uid has been succesfully registered.";



}
?>











<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>
Online PDS | Personal Info
</title>
<script src="pdsjavascript.js"></script>

<link rel="stylesheet" type="text/css" href="pdscss.css">
</head>


<body>


<center>
<form method='POST' action='pdsformpersonalinfo.php'>
<table border=1 cols='3' width='500px'>
<tr><td colspan='3' id='titlehead' class='head'>I. PERSONAL INFORMATION</td></tr>
<tr><td><font color='red' size='3'>*</font>SURNAME</td><td>:</td><td><input type='text' name='surname' size='30' maxlength='50' required='required' class=''></td></tr>
<tr><td><font color='red' size='3'>*</font>FIRST NAME</td><td>:</td><td><input type='text' name='firstname' size='30' maxlength='50' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>MIDDLE NAME</td><td>:</td><td><input type='text' name='middlename' size='30' maxlength='50' required='required'></td></tr>
<tr><td>NAME EXTENSION</td><td>:</td><td><input type='text' name='nameextension' size='30' maxlength='50'></td></tr>
<tr><td><font color='red' size='3'>*</font>DATE OF BIRTH(mm/dd/yyyy)</td><td>:</td><td><input type='date' name='bdate' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>BIRTHPLACE</td><td>:</td><td><input type='text' name='bplace' size='30' maxlength='200' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>SEX</td><td>:</td><td>Male <input type='radio' name='sex' value='Male' required='required'> Female <input type='radio' name='sex' value='Female' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>CIVIL STATUS</td><td>:</td><td><input type='radio' name='civstat' value='Single' required='required'  onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Single 
                            <br><input type='radio' name='civstat' value='Married' required='required'  onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Married 
                            <br><input type='radio' name='civstat' value='Annuled' required='required'  onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Annuled 
                            <br><input type='radio' name='civstat' value='Widowed' required='required'  onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Widowed 
                            <br><input type='radio' name='civstat' value='Seperated' required='required' onclick='document.getElementById("civstaton").setAttribute("disabled","disabled");document.getElementById("civstaton").value = "";'> Seperated 
                            <br><input type='radio' name='civstat' required='required' onclick='document.getElementById("civstaton").removeAttribute("disabled");'> Others, 
                            please specify here<br><input type='text' name='civstat' size='30' id='civstaton' disabled required='required'></td>
                            </tr>
<tr><td><font color='red' size='3'>*</font>CITIZENSHIP</td><td>:</td><td><input type='text' name='citizenship' size='30' maxlength='50' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>HEIGHT (meter)</td><td>:</td><td><input type='number' name='height' size='30' maxlength='10' min='0' max='18' step='0.1' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>WEIGHT (kilogram)</td><td>:</td><td><input type='number' name='weight' size='30' maxlength='10' min='0' max='300' step='0.1' required='required'></td></tr>
<tr><td><font color='red' size='3'>*</font>BLOOD TYPE</td><td>:</td><td><input type='text' name='bloodtype' size='30' maxlength='50' required='required'></td></tr>
<tr><td>GSIS ID NUMBER</td><td>:</td><td><input type='text' name='gsisno' size='30' maxlength='50'></td></tr>
<tr><td>PAG-IBIG ID NUMBER</td><td>:</td><td><input type='text' name='pagibigno' size='30' maxlength='50'></td></tr>
<tr><td>PHILHEALTH NUMBER</td><td>:</td><td><input type='text' name='philhealthno' size='30' maxlength='50'></td></tr>
<tr><td>SSS NUMBER</td><td>:</td><td><input type='text' name='sssno' size='30' maxlength='50'></td></tr>
<tr><td><font color='red' size='3'>*</font>RESIDENTIAL ADDRESS</td><td>:</td><td><textarea name='resadd' style='width:215px;height:100px;' maxlength='500' wrap='physical' style='resize:none' required='required'></textarea></td></tr>
<tr><td><font color='red' size='3'>*</font>ZIP CODE</td><td>:</td><td><input type='text' name='zipcode' size='30' maxlength='50' required='required'></td></tr>
<tr><td>TELEPHONE NUMBER</td><td>:</td><td><input type='tel' name='telno' size='30' maxlength='50'></td></tr>
<tr><td>E-MAIL ADDRESS(if any)</td><td>:</td><td><input type='email' name='emailadd' size='30' maxlength='50'></td></tr>
<tr><td>CELLPHONE NUMBER(if any)</td><td>:</td><td><input type='tel' name='cellno' size='30' maxlength='50'></td></tr>
<tr><td>AGENCY EMPLOYEE NUMBER</td><td>:</td><td><input type='text' name='agencyno' size='30' maxlength='50'></td></tr>
<tr><td>TIN</td><td>:</td><td><input type='text' name='tin' size='30' maxlength='50'></td></tr>
<tr><td colspan='3'><font color='red' size='5'>*</font>Required fields<center>    <input type='submit' name='submitbutton' value='Next'>&nbsp&nbsp&nbsp&nbsp<input   type='reset' value='Reset'></center></td></tr>
</table>
</form>
</center>

</body>


</html>
4

2 に答える 2

0

ほとんどの場合、ユーザーごとに個別のテーブルを作成しているように見えますが、これは非常に悪い考えです。

具体的には、テーブルを作成する SQL を作成していても、実際には使用しないため、これは機能しません。存在しないテーブルに行を挿入しようとしています。

誰かがすぐに飛び込んで、より最新の PHP mysql インターフェイス (mysqli または PDO) を使用するように言うでしょう。彼らは正しいですが、あなたが持っているセットアップのためのより良いロジックを提案するだけです:

$surnamex = mysql_real_escape_string($_POST["surname"]);
$firstnamex = mysql_real_escape_string($_POST["firstname"]);
$middlenamex = mysql_real_escape_string($_POST["middlename"]);
$nameextensionx = mysql_real_escape_string($_POST["nameextension"]);
$bdatex = mysql_real_escape_string($_POST["bdate"]);
$bplacex = mysql_real_escape_string($_POST["bplace"]);
$sexx = mysql_real_escape_string($_POST["sex"]);
$civstatx = mysql_real_escape_string($_POST["civstat"]);
$citizenshipx = mysql_real_escape_string($_POST["citizenship"]);
$heightx = mysql_real_escape_string($_POST["height"]);
$weightx = mysql_real_escape_string($_POST["weight"]);
$bloodtypetx = mysql_real_escape_string($_POST["bloodtype"]);
$gsisnox = mysql_real_escape_string($_POST["gsisno"]);
$pagibignox = mysql_real_escape_string($_POST["pagibigno"]);
$philhealthnox = mysql_real_escape_string($_POST["philhealthno"]);
$sssx = mysql_real_escape_string($_POST["sssno"]);
$resaddx = mysql_real_escape_string($_POST["resadd"]);
$zipcodex = mysql_real_escape_string($_POST["zipcode"]);
$telnox = mysql_real_escape_string($_POST["telno"]);
$emailaddx = mysql_real_escape_string($_POST["emailadd"]);
$cellnox = mysql_real_escape_string($_POST["cellno"]);
$agencynox = mysql_real_escape_string($_POST["agencyno"]);
$tin = mysql_real_escape_string($_POST["tin"]);

$uid = mysql_real_escape_string($uid);

if($_POST['submitbutton'] == "submit")
{
  // a single "users" table, with one row per user, including the uid

  $sql = "CREATE TABLE if not exist users
        ( _key INT NOT NULL AUTO_INCREMENT,
        uid TEXT(50) NOT NULL
        , surname  TEXT(50) NOT NULL DEFAULT '?'
        , firstname  TEXT(50) NOT NULL DEFAULT '?'
        , middlename  TEXT(50) NOT NULL DEFAULT '?'
        , nameextension  TEXT(50) NOT NULL DEFAULT '?'
        , bdate  DATE NOT NULL DEFAULT '?'
        , bplace  TEXT(200) NOT NULL DEFAULT '?'
        , sex  TEXT NOT NULL DEFAULT '?'
        , civstat  TEXT NOT NULL DEFAULT '?'
        , citizenship  TEXT(50) NOT NULL DEFAULT '?'
        , height  INT(10) NOT NULL DEFAULT '?'
        , weight  INT(10) NOT NULL DEFAULT '?'
        , bloodtype  TEXT(50) NOT NULL DEFAULT '?'
        , gsisno  TEXT(50) NOT NULL DEFAULT '?'
        , pagibigno  TEXT(50) NOT NULL DEFAULT '?'
        , philhealthno  TEXT(50) NOT NULL DEFAULT '?'
        , sssno  TEXT(50) NOT NULL DEFAULT '?'
        , resadd  TEXT(500) NOT NULL DEFAULT '?'
        , zipcode  TEXT(50) NOT NULL DEFAULT '?'
        , telno  INT(20) NOT NULL DEFAULT '?'
        , emailadd  TEXT(50) NOT NULL DEFAULT '?'
        , cellno  int(20) NOT NULL DEFAULT '?'
        , agencyno  TEXT(50) NOT NULL DEFAULT '?'
        , tin  TEXT(50) NOT NULL DEFAULT '?'
        , PRIMARY KEY (_key))";

        mysql_query($sql) or die (mysql_error());

        $query="INSERT INTO users (uid, surname,firstname,middlename,nameextension,bdate,bplace,sex,civstat,citizenship,height,weight,bloodtype,gsisno,pagibigno,philhealthno,sssno,resadd,zipcode,telno,emailadd,cellno,agencyno,tin)VALUES('$uid',$surnamex','$firstnamex','$nameextensionx','$bdatex','$bplacex','$sexx','$civstatx','$citizenshipx','$heightx','$weightx','$bloodtypex','$gsisnox','$pagibignox','$philhealthnox','$sssnox','$resaddx','$zipcodex','$telnox','$emailaddx','$cellnox','$agencynox','$tinx')";

        mysql_query($query) or die (mysql_error());
        echo "The user $uid has been succesfully registered.";

}
于 2013-05-10T01:41:46.123 に答える
0

$uidユーザーごとにテーブルを作成していますか? その場合は、ユーザー情報の保存方法が間違っています。私の提案は、最初に上で既に定義したようなテーブルを作成し、それを示す列をもう 1 つ追加usernameしてから、そのテーブルの各行にユーザー情報を格納することです。

また、定義しているテーブルの構造にもいくつかのエラーがあります。たとえば、TEXTタイプ列にデフォルト値を設定することはできません。

もう 1 つ、列名をバッククォート (`) 文字で囲むようにしてください。場合によっては、mysql で関数または事前定義された名前である名前を選択した可能性があり、それが問題を引き起こす可能性があります。

$sqlまた、変数に対して mysql_query を実行していません。

于 2013-05-10T01:43:20.733 に答える