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您是否为每个用户创建一个表?如果是这种情况,那么您选择了错误的方式来存储用户信息。我的建议是首先创建一个您已经在上面定义的表,然后再添加一列指示username然后将用户信息存储在该表的每一行中。

同样在您定义的表结构中存在几个错误。例如,TEXT类型列不能有默认值。

还有一件事,尝试在反引号 (`) 字符之间使用列名。在某些情况下,您可能选择了一个函数名称或 mysql 中的某个预定义名称,这可能会导致问题。

此外,您还没有在$sql变量上运行 mysql_query。

于 2013-05-10T01:43:20.733 回答