Parameterized queries in PHP with MySQL connection

前端 未结 2 1251
一向
一向 2020-12-07 02:10

I\'ve read about SQL injection so I tried it with my site and of course it worked.. I know that the solution is parameterized queries and I also know that there are a lot of

相关标签:
2条回答
  • 2020-12-07 02:39

    use:

    $userPass = mysqli_real_escape_string($mysqli,$_POST["password"]);
    

    This block the '' or '=' thing thing :) where $mysqli is your connection string ofc.

    0 讨论(0)
  • 2020-12-07 02:45

    Here you go

    $stmt = mysqli_prepare($dbc, "SELECT * FROM users WHERE username = ? AND password = ?");
    mysqli_stmt_bind_param($stmt, "s", $userName);
    mysqli_stmt_bind_param($stmt, "s", $userPass);
    mysqli_stmt_execute($stmt);
    $row = mysqli_stmt_fetch($stmt);
    

    Documentation

    As side note i would reccomend to encrypt your password or better use hash for security, it's not good to store password as plain text

    0 讨论(0)
提交回复
热议问题