在MySQL DB中创建用户

时间:2018-04-24 12:54:37

标签: php html

您好我正在尝试编写脚本来为安全登录/注册页面创建用户。建议的解决方案的一部分是:

CREATE USER "sec_user"@'localhost' IDENTIFIED BY 'eKcGZr59zAa2BEWU';
GRANT SELECT, INSERT, UPDATE ON "secure_login".* TO "sec_user"@'localhost';

当我使用它时 - 它突出显示@符号上的错误,如果我删除所有引号,它会突出显示错误的' BY' - 我不确定为什么。

1 个答案:

答案 0 :(得分:0)

我认为您的问题可能就是混合单引号和双引号的方式。 尝试如下所示的确切语法,这可能会解决问题

CREATE USER 'sec_user'@'localhost' IDENTIFIED BY 'eKcGZr59zAa2BEWU'; GRANT SELECT, INSERT, UPDATE ON secure_login.* TO 'sec_user'@'localhost';

上面应该可以创建一个用户,但是你的目标实际上是为下面的用户创建注册是我自己的一个项目的实现。您首先需要在youe数据库中创建一个customer表,然后在下面创建一个....

<?php


        $con = mysqli_connect("<yourHOST>","<yourUSER>",",<yourPASSWORD">,"<yourDBname>");
    if (mysqli_connect_errno()) {
        echo"
            Failed to connect to the MySQL DB:".mysqli_connect_error();
        }

    /getting the ip address of the customer
function getIp() {

    $ip = $_SERVER['REMOTE_ADDR'];
        if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
            $ip = $_SERVER['HTTP_CLIENT_IP'];}
        elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])){
            $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
        }

    return $ip;

    if (isset($_POST['cust_acc'])) {
        global $con;
        $ip = getIP();
        $cust_name = $_POST['cust_name'];
        $cust_email = $_POST['cust_email'];
        $cust_pass = $_POST['cust_pass'];
        $cust_image = $_FILES['cust_img']['name'];
        $cust_image_tmp = $_FILES['cust_img']['tmp_name'];
        $cust_ctry = $_POST['cust_ctry'];
        $cust_city = $_POST['cust_city'];
        $cust_contact = $_POST['cust_cont'];
        $cust_addr = $_POST['cust_addr'];


        $check_email = "SELECT * FROM customers WHERE customer_email='$cust_email'";
        $run_check_email = mysqli_query($con, $check_email);
        $check_rows = mysqli_fetch_array($run_check_email);
        $checked_email = $check_rows['customer_email'];

        if ($checked_email==$cust_email){
            echo "
                <script>alert('User Already Exists with submitted Email')</script>";
            echo "<script>window.open('checkout.php','_self')</script>
            ";

        }
        else{
        move_uploaded_file($cust_image_tmp,"customer/customer_images/$cust_image");
        $insert_cust = "INSERT INTO customers(customer_ip,customer_name,customer_email,customer_pass,customer_country,customer_city,customer_contact,customer_image,customer_address) 
VALUES('$ip','$cust_name','$cust_email','$cust_pass','$cust_ctry','$cust_city','$cust_contact','$cust_image','$cust_addr')";

        $run_insert = mysqli_query($con, $insert_cust);