-1

I am trying to do a simple connection mysql server. but when ever I try to enter data or connect to the database, I get this error.

Fatal error: Uncaught Error: Call to undefined function mysql_select_db() in E:\wamp64\www\admin\adminpanel\login.php on line 99 ( ! ) Error: Call to undefined function mysql_select_db() in E:\wamp64\www\admin\adminpanel\login.php on line 99

below my php code ;

<?php require_once('connect.php'); ?>

<?php

if (!function_exists("GetSQLValueString")) {

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 

{

  if (PHP_VERSION < 6) {

    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  }


  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);


  switch ($theType) {

    case "text":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;    

    case "long":

    case "int":

      $theValue = ($theValue != "") ? intval($theValue) : "NULL";

      break;

    case "double":

      $theValue = ($theValue != "") ? doubleval($theValue) : "NULL";

      break;

    case "date":

      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

      break;

    case "defined":

      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

      break;

  }

  return $theValue;

}

}

?>

<?php

// *** Bu sitede giriş isteklerini doğrula.

if (!isset($_SESSIBuN)) {

  session_start();

}


$loginFormAction = $_SERVER['PHP_SELF'];

if (isset($_GET['accesscheck'])) {

  $_SESSION['PrevUrl'] = $_GET['accesscheck'];

}


if (isset($_POST['kullanici_adi'])) {

  $loginUsername=$_POST['kullanici_adi'];

  $password=$_POST['kullanici_sifre'];

  $MM_fldUserAuthorization = "";

  $MM_redirectLoginSuccess = "index.php";

  $MM_redirectLoginFailed = "login.php";

  $MM_redirecttoReferrer = false;

  mysql_select_db('form_database', $conn);



  $LoginRS__query=sprintf("SELECT kullanici_adi, kullanici_sifre FROM admin_yoneticiler WHERE kullanici_adi=%s AND kullanici_sifre=%s",

    GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text")); 



  $LoginRS = mysql_query($LoginRS__query, $admin) or die(mysql_error());

  $loginFoundUser = mysql_num_rows($LoginRS);

  if ($loginFoundUser) {

     $loginStrGroup = "";



    if (PHP_VERSION >= 5.1) {session_regenerate_id(true);} else {session_regenerate_id();}

    //declare two session variables and assign them

    $_SESSION['MM_Username'] = $loginUsername;

    $_SESSION['MM_UserGroup'] = $loginStrGroup;          


    if (isset($_SESSION['PrevUrl']) && false) {

      $MM_redirectLoginSuccess = $_SESSION['PrevUrl'];    

    }

    header("Location: " . $MM_redirectLoginSuccess );

  }

  else {

    header("Location: ". $MM_redirectLoginFailed );

  }

}

?>

  <meta charset="utf-8">

  <meta http-equiv="X-UA-Compatible" content="IE=edge">

  <title>Form Kontrol Paneli Giriş</title>

  <!-- Latest compiled and minified CSS -->

  <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css">

  <style type="text/css" media="screen">

    .col-md-offset-36 {

      margin-left: 36%;

    }


    .margin-top20 {

      margin-top: 20px;

    }


    .margin-top100 {

      margin-top: 100px !important;

    }


    .b-white {

      background-color: #fff;

    }


    .content {

      min-height: 540px;

    }


    .footer {

      border-top: 1px solid #EDEDED;

    }


    .makeauthor {

      float: right;

    }

  </style>



  </style>


  <!-- Latest compiled and minified JavaScript -->

  <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>

  <div class="container margin-top100">

  <div class="row">

      <div class="col-md-4 col-md-offset-36">

          <a href="./index.php"><img src="img/your_logo.png" alt="Form Kontrol Paneli"></a>

      </div>

      <div class="col-md-4 col-md-offset-4">

          <div class="panel panel-default">

              <div class="panel-body">

                  <h5 class="text-center">

                      Yönetici Girişi</h5>

                  <form class="form form-signup" role="form" name="login" method="POST" action="<?php echo $loginFormAction; ?>">

                  <div class="form-group">

                      <div class="input-group">

                          <span class="input-group-addon"><span class="glyphicon glyphicon-user"></span></span>

                          <input type="text" name="kullanici_adi" class="form-control" placeholder="Yönetici Adınız" />

                      </div>

                  </div>

                  <div class="form-group">

                      <div class="input-group">

                          <span class="input-group-addon"><span class="glyphicon glyphicon-lock"></span></span>

                          <input type="password" name="kullanici_sifre" class="form-control" placeholder="Yönetici Şifreniz" />

                      </div>

                  </div>

                  </div>

                  <button type="submit" name="giris" class="btn btn-sm btn-primary btn-block" role="button">Giriş Yap</button>

                  </form>



          </div>

      </div>

      </div>

ArtOsi
  • 893
  • 6
  • 13
Bekir
  • 29
  • 1
  • 1
  • 4

1 Answers1

3

You should use mysqli_connect instead of mysql_connect for latest php version

    $link = mysqli_connect("$host", "$username", "$password")or die("cannot connect"); 
    mysqli_select_db($link, $db_name)or die("cannot select DB");

or try pdo

<?php
    $db=new PDO('mysql:host=localhost;dbname=$dbname;charset=utf8mb4', 'root', '') or die("Could connect to Database");
?>
Bhargav Chudasama
  • 6,348
  • 3
  • 19
  • 37
  • It's a bad advice. Better use PDO. – MVG1984 Jul 20 '17 at 06:34
  • i try this codes but :( Warning: mysqli_select_db() expects parameter 1 to be mysqli, string given in E:\wamp64\www\admin\adminpanel\login.php on line 99 Call Stack # Time Memory Function Location 1 0.0016 386904 {main}( ) ...\login.php:0 2 0.0060 402968 mysqli_select_db ( ) ...\login.php:99 ( ! ) Fatal error: Uncaught Error: Call to undefined function mysql_escape_string() in E:\wamp64\www\admin\adminpanel\login.php on line 18 ( ! ) Error: Call to undefined function mysql_escape_string() in E:\wamp64\www\admin\adminpanel\login.php on line 18 – Bekir Jul 20 '17 at 06:35
  • @Bekir, you better change your mysql_ or mysqli_ code to PDO. Yes, it will take a bit more time then replace to mysqli_ and configure it, but you throw off a big headache in the future:) – MVG1984 Jul 20 '17 at 06:38
  • you should @MVG1984 – Bhargav Chudasama Jul 20 '17 at 06:42
  • @MVG1984 What is your argument for preferring PDO over MySQLi? Why should we use PDO over MySQLi? – Fjarlaegur Jul 20 '17 at 06:51
  • Because you can use parametrized queries. PDO can work not only with mysql etc. And one day, mysqli_will be removed too. I prefer to be prepared for it, then after some time ask "why mysqli_ doesnt work" again :) Read this interesting artilce PDO vs MYSQL - https://code.tutsplus.com/tutorials/pdo-vs-mysqli-which-should-you-use--net-24059 – MVG1984 Jul 20 '17 at 06:56
  • @MVG1984 i am new php coder bro can u help me ? i didnt to this – Bekir Jul 20 '17 at 06:59
  • `global $conn; mysqli_select_db($conn,'form_database'); // $db=new PDO('mysql:host=localhost;dbname=$dbname;charset=utf8mb4', 'root', '') or die("Could connect to Database");` change in login.php @Bekir – Bhargav Chudasama Jul 20 '17 at 07:29
  • @Bhargav which line bro ?? 100.line ?? – Bekir Jul 20 '17 at 08:27