doumi9618 2017-03-19 23:03
浏览 39

为每个注册的成员创建一个新表

How could i include in the include.php file that whenever the code is set there is also another function added, which would be something like:

 $query = "CREATE TABLE IF NOT EXISTS (here would be post parameter email from java file) (
        id INT NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(id),
        DATE    DATETIME NOT NULL,
        PAIN INT(11) UNSIGNED NOT NULL
    )" 

So this means when a user clicks register he would be added to the users table and also a new table would be created where the name of the table would be his email!

include.php:

<?php

require_once 'include/DB_Functions.php';
$db = new DB_Functions();

// json response array
$response = array("error" => FALSE);

if (isset($_POST['name']) && isset($_POST['email']) && isset($_POST['password'])) {

    // receiving the post params
    $name = $_POST['name'];
    $email = $_POST['email'];
    $password = $_POST['password'];



    // check if user is already existed with the same email
    if ($db->isUserExisted($email)) {
        // user already existed
        $response["error"] = TRUE;
        $response["error_msg"] = "Uporabnik že obstaja " . $email;
        echo json_encode($response);
    } else {
        // create a new user
        $user = $db->storeUser($name, $email, $password);
        if ($user) {
            // user stored successfully
            $response["error"] = FALSE;
            $response["uid"] = $user["unique_id"];
            $response["user"]["name"] = $user["name"];
            $response["user"]["email"] = $user["email"];
            $response["user"]["created_at"] = $user["created_at"];
            $response["user"]["updated_at"] = $user["updated_at"];
            echo json_encode($response);
        } else {
            // user failed to store
            $response["error"] = TRUE;
            $response["error_msg"] = "Neznana napaka!";
            echo json_encode($response);
        }
    }
} else {
    $response["error"] = TRUE;
    $response["error_msg"] = "Manjkajo paramatri (name, email or password)!";
    echo json_encode($response);
}
?>

Any help or ideas on how to implement that would be very helpfull.

  • 写回答

1条回答 默认 最新

  • dongtang5057 2017-03-19 23:12
    关注

    You need backticks to enclose your table name, because the @-sign will lead to non syntax-conform table name:

    $query = "
        CREATE TABLE IF NOT EXISTS `{$_POST["email"]}` (
        id INT NOT NULL AUTO_INCREMENT,
        PRIMARY KEY(id),
        DATE    DATETIME NOT NULL,
        PAIN INT(11) UNSIGNED NOT NULL
    )" 
    

    I gracefully assume, that $_POST["email"] has been checked on sanity beforehand.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应
  • ¥15 matlab基于pde算法图像修复,为什么只能对示例图像有效
  • ¥100 连续两帧图像高速减法
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作