v2.5.2
Giriş yap

Admin Paneli Bağlantı Hatası

yahyairis
169 defa görüntülendi

Merhabalar,
xampp eski sürümümünde web sitem sorunsuz açılıyordu yanlış hatırlamıyorsam sürüm 6 ya da 7 di. Şimdi 8 e güncelledim ve admin paneline giriş yapmak istediğim zaman ekteki hatayı alıyorum;

"
Fatal error: Uncaught mysqli_sqFatal error: Uncaught mysqli_sql_exception: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1 in C:\xampp\htdocs\a\panel\login.php:130 Stack trace: #0 C:\xampp\htdocs\yahyairis\nedmin\login.php(130): mysqli_query(Object(mysqli), 'SELECT username...') #1 {main} thrown in C:\xampp\htdocs\a\panel\login.php on line 130

"

Eski sürümde problemsiz çalışıyor, ne yapmam gerekiyor?

    <?php ob_start();
    session_start();



        // LOGIN SCRIPT


      /* DATABASE CONNECTION*/


        $db['db_host'] = 'localhost';
        $db['db_user'] = 'root';
        $db['db_pass'] = '';
        $db['db_name'] = 'test';
      foreach($db as $key=>$value){
          define(strtoupper($key),$value);
      }
      global $conn;
      $conn = mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME);
      if(!$conn){
          die("Cannot Establish A Secure Connection To The Host Server At The Moment!");
      }

      try{
          $db = new PDO('mysql:dbhost=localhost;dbname=test;charset=utf8','root','');


      }
      catch(Exception $e){

          die('Cannot Establish A Secure Connection To The Host Server At The Moment!');
      }

      /*DATABASE CONNECTION */


      // Define variables and initialize with empty values

      $username = $password = "";

      $username_err = $password_err = "";



      // Processing form data when form is submitted

      if($_SERVER["REQUEST_METHOD"] == "POST"){



          // Check if username is empty

          if(empty(trim($_POST["username"]))){

              $username_err = 'Kullanıcı Adınızı Girini!.';

          } else{

              $username = trim($_POST["username"]);

          }



          // Check if password is empty

          if(empty(trim($_POST['password']))){

              $password_err = 'Şifrenizi Giriniz!';

          } else{

              $password = trim($_POST['password']);

          }



          // Validate credentials

          if(empty($username_err) && empty($password_err)){

              // Prepare a select statement

              $sql = "SELECT username, password FROM admin WHERE username = ? ";



              if($stmt = mysqli_prepare($conn, $sql)){

                  // Bind variables to the prepared statement as parameters

                  mysqli_stmt_bind_param($stmt, "s", $param_username);

                  // Set parameters

                  $param_username = $username;

                  // Attempt to execute the prepared statement

                  if(mysqli_stmt_execute($stmt)){

                      // Store result

                      mysqli_stmt_store_result($stmt);

                      // Check if username exists, if yes then verify password

                      if(mysqli_stmt_num_rows($stmt) == 1){

                          // Bind result variables

                          mysqli_stmt_bind_result($stmt, $username, $hashed_password);

                          if(mysqli_stmt_fetch($stmt)){

                              if(password_verify($password, $hashed_password)){

                                  /* Password is correct, so start a new session and

                                  save the username to the session */

                                  

                                  $_SESSION['username'] = $username;

                                  // $sql = "SELECT department FROM employees WHERE username='$username'" ;
                                  $statement = mysqli_query($conn, $sql);

                                    header("Location: index.php");

                                // Close statement

                                //mysqli_stmt_close($statement);

                                //header("location: sales");

                              } else{

                                  // Display an error message if password is not valid

                                  $password_err = 'Girdiğiniz şifre geçerli değildi. Lütfen tekrar deneyin.';

                              }

                          }

                      } else{

                          // Display an error message if username doesn't exist

                          $username_err = 'Bu kullanıcı adına sahip bir hesap bulunamadı. Lütfen yeniden kontrol edin ve tekrar deneyin.';

                      }

                  } else{

                      echo "Oops! Bir şeyler yanlış gitti. Lütfen daha sonra tekrar deneyiniz.";

                  }

              }



              // Close statement

              mysqli_stmt_close($stmt);

          }



          // Close connection

          mysqli_close($conn);

      }



      ?>

    <!--- LOGIN SCRIPT----->
Cevap yaz
Cevaplar (4)
bhebatu
257 gün önce

<?php
ob_start();
session_start();

// LOGIN SCRIPT

/* DATABASE CONNECTION */

$db['db_host'] = 'localhost';
$db['db_user'] = 'root';
$db['db_pass'] = '';
$db['db_name'] = 'test';

foreach ($db as $key => $value) {
    define(strtoupper($key), $value);
}

global $conn;
$conn = mysqli_connect(DB_HOST, DB_USER, DB_PASS, DB_NAME);

if (!$conn) {
    die("Cannot Establish A Secure Connection To The Host Server At The Moment!");
}

try {
    $db = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');
} catch (Exception $e) {
    die('Cannot Establish A Secure Connection To The Host Server At The Moment!');
}

/* DATABASE CONNECTION */

// Define variables and initialize with empty values
$username = $password = "";
$username_err = $password_err = "";

// Processing form data when the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {

    // Check if the username is empty
    if (empty(trim($_POST["username"]))) {
        $username_err = 'Kullanıcı Adınızı Girin!.';
    } else {
        $username = trim($_POST["username"]);
    }

    // Check if the password is empty
    if (empty(trim($_POST['password']))) {
        $password_err = 'Şifrenizi Girin!';
    } else {
        $password = trim($_POST['password']);
    }

    // Validate credentials
    if (empty($username_err) && empty($password_err)) {

        // Prepare a select statement
        $sql = "SELECT username, password FROM admin WHERE username = ? ";

        if ($stmt = mysqli_prepare($conn, $sql)) {
            // Bind variables to the prepared statement as parameters
            mysqli_stmt_bind_param($stmt, "s", $param_username);

            // Set parameters
            $param_username = $username;

            // Attempt to execute the prepared statement
            if (mysqli_stmt_execute($stmt)) {
                // Store result
                mysqli_stmt_store_result($stmt);

                // Check if the username exists, if yes then verify the password
                if (mysqli_stmt_num_rows($stmt) == 1) {
                    // Bind result variables
                    mysqli_stmt_bind_result($stmt, $username, $hashed_password);

                    if (mysqli_stmt_fetch($stmt)) {
                        if (password_verify($password, $hashed_password)) {
                            /* Password is correct, so start a new session and
                            save the username to the session */
                            $_SESSION['username'] = $username;

                            header("Location: index.php");
                        } else {
                            // Display an error message if the password is not valid
                            $password_err = 'Girdiğiniz şifre geçerli değil. Lütfen tekrar deneyin.';
                        }
                    }
                } else {
                    // Display an error message if the username doesn't exist
                    $username_err = 'Bu kullanıcı adına sahip bir hesap bulunamadı. Lütfen yeniden kontrol edin ve tekrar deneyin.';
                }
            } else {
                echo "Oops! Bir şeyler yanlış gitti. Lütfen daha sonra tekrar deneyin.";
            }
        }

        // Close statement
        mysqli_stmt_close($stmt);
    }

    // Close connection
    mysqli_close($conn);
}
?>
<!--- LOGIN SCRIPT------>


ebykdrms
260 gün önce

Çok da detaylı inceleyemedim ama sanki şu satırların sıralaması hatalı:

// Bind variables to the prepared statement as parameters
mysqli_stmt_bind_param($stmt, "s", $param_username);

// Set parameters
$param_username = $username;

Yani $param_username değişkenine henüz değer atamamışken bind etmeye çalışıyor olabilirsin. Bu da "?" karakteri yerine değer girilememesine neden oluyordur. Çünkü aldığın hata da "?" ile alakalı:
You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '?' at line 1

web0x1e
261 gün önce

dsadadadad

web0x1e
261 gün önce

test