如何通过php中的textbox字段在phpmyadmin中创建表

时间:2018-03-08 08:06:53

标签: php mysql phpmyadmin

<!DOCTYPE html5>
<html>
<head>
<title>Exotic Group</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://www.w3schools.com/w3css/3/w3.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
</head>
<body>


<h1 style="text-align: center;">EXOTIC GROUP CAMPAIGN</h1>

<!-- FORM -->
<form name="New_Campaign"  method="post" class="w3-container w3-card-4 w3-light-grey w3-text-blue w3-margin" onsubmit="alert('1 record added')">

<h2 class="w3-center">Enter your details</h2>

<!--Customer ID --> 
<div class="w3-row w3-section">
<label class="w3-text-red"><b>ENTER CAMPAIGN NAME</b></label>
  <div class="w3-col" style="width:50px; margin-top:20px"><i class="w3-xxlarge fa fa-building-o"></i>
  </div>
    <div class="w3-rest">
          <input class="w3-input w3-border" name="campaign_name" type="text" required>
    </div>
</div>

<!--SUBMIT BUTTON-->
<div class="container" style="text-align: center;">
<p><button class="w3-btn w3-green w3-round-large w3-text-shadows w3-hover-light-green" type="submit" name="submit"><b>SUBMIT</b></button></p>
</div>
</form>

<?php

//Establishing  Connection with Server
$connection = mysql_connect("localhost", "root", "");

if (!$connection)
    {
        die('Could not connect: ' . mysql_error());
    }

//Selecting Database
mysql_select_db("exotic_group", $connection);

$campaign_name = $_POST['campaign_name'];

// Create a MySQL table in the selected database
mysql_query("CREATE TABLE $campaign_name ('Cust_ID' int(11) NOT NULL AUTO_INCREMENT,
                                         'MSISDN' varchar(15) NOT NULL,
                                         'Code' varchar(8) NOT NULL,
                                         'Delivery_Status' tinyint(3) NOT NULL,
                                         'Delivery_Timestamp' datetime DEFAULT NULL,
                                         'Message_ID' varchar(20) NOT NULL,
                                         'AdViewCount' int(11) NOT NULL,
                                         'CTACount' int(11) NOT NULL,
                                          PRIMARY KEY (`Cust_ID`)
                                         ) ENGINE=InnoDB DEFAULT CHARSET=latin1")

or 

die(mysql_error());

?>

</body>
</html>

我收到以下错误:

  

您的SQL语法有错误;检查与您的MariaDB服务器版本对应的手册,以便在&#39;(&#39; Cust_ID&#39; int(11)NOT NULL AUTO_INCREMENT,&#39; MSISDN&#39; varchar(15)附近使用正确的语法不在第1行

  

该表未出现在PHPMYADMIN界面的选定数据库中。

欢迎任何评论。

1 个答案:

答案 0 :(得分:1)

您必须从所有字段中删除单引号(')。

mysql_query("CREATE TABLE $campaign_name (Cust_ID int(11) NOT NULL AUTO_INCREMENT,
                                     MSISDN varchar(15) NOT NULL,
                                     Code varchar(8) NOT NULL,
                                     Delivery_Status tinyint(3) NOT NULL,
                                     Delivery_Timestamp datetime DEFAULT NULL,
                                     Message_ID varchar(20) NOT NULL,
                                     AdViewCount int(11) NOT NULL,
                                     CTACount int(11) NOT NULL,
                                      PRIMARY KEY (`Cust_ID`)
                                     ) ENGINE=InnoDB DEFAULT CHARSET=latin1")