创建SQL表的PHP表单

时间:2014-06-09 12:23:43

标签: php mysql

我有一个PHP表单,它将信息推送到一个PHP脚本,将信息添加到SQL数据库,我想创建一个也将创建一个新表的事件。这是我目前的代码

 $sql = "CREATE TABLE ".$ac_system." (id INT NOT NULL AUTO_INCREMENT , PRIMARY KEY 
 (id) , account_nr CHAR(10) , credits CHAR(10))";    //Edited This Section from VAR to CHAR
 if (mysql_query($sql, $con)) {
            $insertSuccessful = true;
        } else {
            echo $sql;
            print_r($_POST);
            echo "\n" . mysql_error($con);
            echo "mysql err no : " . mysql_errno($con);
        }
        $sql1 = "insert into etrack_clients set     
        ac_name = '".$ac_name."',
        ac_ck = '".$ac_ck."',
        ac_ckdoc2 = '".$ac_ckdoc2."'" ;

    if (mysql_query($sql1, $con)) {
            $insertSuccessful = true;
        } else {
            echo $sql1;
            print_r($_POST);
            echo "\n" . mysql_error($con);
            echo "mysql err no : " . mysql_errno($con);

SQL1本身可以正常工作但是只要我第一次添加SQL就会停止工作,这就是我得到的错误

 CREATE TABLE TREVOR123 (id INT NOT NULL AUTO_INCREMENT , PRIMARY KEY (id) , account_nr 
 VAR(10) , credits VAR(10))Array ( [ac_name] => Test [ac_psira] => Test [ac_ck] => Test 
 [ac_system] => TREVOR123 [ac_contactp] => Test [ac_contnr] => Test [ac_fax] => 
 [ac_email] => [ac_date] => [ac_account] => Prepaid [ac_payment] => COD 
 [ac_paymentdate] => [ac_notes] => [submit] => Submit ) You have an error in your SQL 
 syntax; check the manual that corresponds to your MySQL server version for the right 
 syntax to use near 'VAR(10) , credits VAR(10))' at line 1mysql err no : 1064

我只需要创建表格,表格将从另一个屏幕填充

2 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

更改此行:

VAR(10) , credits VAR(10))Array ( [ac_name] => Test [ac_psira] => Test [ac_ck] => Test 

为:

VARCHAR(10) , credits VARCHAR(10))Array ( [ac_name] => Test [ac_psira] => Test [ac_ck] => Test

您可以在此处找到MySQL数据类型列表:

http://dev.mysql.com/doc/refman/5.0/en/string-type-overview.html