简体   繁体   English

这个php代码有问题吗?

[英]is there something wrong with this php code?

is this piece of code correct syntax wise ?这段代码的语法正确吗?

I need to update some fields in a certain row in my database which i can access using email ... so is this right ?我需要更新我可以使用电子邮件访问的数据库中某行中的一些字段……这是对的吗?

public function storeData($emaill, $servicee, $ratee, $rated_clientss) {
    $email = "samy@gmail.com";
    $service = "lksdjfsdkljf";
    $rate = "good";
    $rated_clients = "20";
    $stmt = $this->conn->prepare ( "UPDATE users SET service='$service' and SET rate='$rate' and SET rated_clients='$rated_clients' WHERE email='$email'" );
    var_dump($stmt->execute ());

    if ($stmt->execute ()) {
        $data = $stmt->get_result ()->fetch_assoc ();
        $stmt->close ();
        return $data;
    } else {
        return NULL;
    }
}

Prepared statments to not directly accept user input, instead, you need to pass them as a placeholder: ?准备好的语句不直接接受用户输入,而是需要将它们作为占位符传递: ? , and then use bind_param() to fill in the type and the variable. ,然后使用bind_param()填入类型和变量。

Observe:观察:

$stmt = $this->conn->prepare ( "UPDATE users SET service=? and SET rate=? and SET rated_clients=? WHERE email=?" );
$stmt->bind_param('ssss', $service, $rate, $rated_clients, $email);

Now you can correctly ->execute the $stmt .现在您可以正确->execute $stmt

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM