duanlinma5885 2016-03-17 23:55
浏览 58
已采纳

创建一个包含会话名称的php表

i can't find the answer for this anywhere. but very simply i have a create table and a saved session. i need that session to be the table name. this is shown below. i have struggled with this and have tried to find an answer everywhere.

below is the create msql table. the session is $id and below is what i have tried so far.

$sql = "CREATE TABLE " . $id . " (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
firstname VARCHAR(30) NOT NULL,
lastname VARCHAR(30) NOT NULL,
email VARCHAR(50),
reg_date TIMESTAMP
)";

this is the page in context (updated)

<?php
//header("Location:all_games/myscorenum.php");
$servername = "localhost";
$username = "root";
$password = "root";
$dbname = "score";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

session_start();
$id=$_SESSION['id'];

echo"$id";


 $sql = "CREATE TABLE '" . $id . "' (
   id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
    firstname VARCHAR(30) NOT NULL,
    lastname VARCHAR(30) NOT NULL,
    email VARCHAR(50),
     reg_date TIMESTAMP
   ) ";
if ($conn->query($sql) === TRUE) {
    echo "Table MyGuests created successfully";
} else {
    echo "Error creating table: " . $conn->error;
}

$conn->close();
?>

</div>

展开全部

  • 写回答

2条回答 默认 最新

  • duanli6618 2016-03-18 00:42
    关注

    Try to use this query

      $sql = "CREATE TABLE '. $id .' (
       id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
        firstname VARCHAR(30) NOT NULL,
        lastname VARCHAR(30) NOT NULL,
        email VARCHAR(50),
         reg_date TIMESTAMP
       ) ";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部