1

I don't know what I'm doing wrong but I receive this error:-

Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in C:\wamp\www\includes\config.php on line 7

How can I fix this?

<?php
$mysql_hostname = "localhost";
$mysql_user = "bootstrapadmin";
$mysql_password = "";
$mysql_database = "bootstrap";

$bd = mysql_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you fucked something up!");
mysql_select_db($mysql_database, $bd) or die("Mate you fucked something up!");
?>

Now I'm running into the problem with my login page

Warning: mysqli_query() expects at least 2 parameters, 1 given in C:\wamp\www\login.php on line 12
Call Stack
#   Time    Memory  Function    Location
1   0.0012  140512  {main}( )   ..\login.php:0
2   0.0079  149352  mysqli_query ( )    ..\login.php:12

( ! ) Warning: mysql_num_rows() expects parameter 1 to be resource, null given in C:\wamp\www\login.php on line 13
Call Stack
#   Time    Memory  Function    Location
1   0.0012  140512  {main}( )   ..\login.php:0
2   0.0960  149752  mysql_num_rows ( )  ..\login.php:13

<?php

session_start();
include("includes/config.php");

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    //username and password sent from form
    $myusername = addslashes($_POST['username']);
    $mypassword = md5(addslashes($_POST['password']));

    $sql = "SELECT userid FROM tbl_users WHERE username='$myusername' and password='$mypassword'";
    $result = mysqli_query($sql);
    $count = mysql_num_rows($result);

    // If result matched $myusername and $mypassword, table row must be 1 row
    if ($count == 1) {
        //$session_register("myusername");
        $_SESSION['login_admin'] = $myusername;
        header("location: http://localhost/admin/");
    }
}
?>
vimuth
  • 5,064
  • 33
  • 79
  • 116

2 Answers2

1

mysql_* functions are no longer supported. You can use mysqli_* functions instead. For eg:

<?php
$mysql_hostname = "localhost";
$mysql_user = "bootstrapadmin";
$mysql_password = "";
$mysql_database = "bootstrap";

$bd = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you messed something up!");
mysqli_select_db($mysql_database, $bd) or die("Mate you messed something up!");
?>
Nisar P
  • 316
  • 2
  • 9
0

Have you searched for MySQLi or PDO? The old mysql_* methods are deprecated and will be removed in the upcoming versions of PHP.

In my opinion PDO is the best way to go, but just converting to MySQLi should be sufficient. Just research a little and use one of these newer techniques.

For MySQLi basically just change the two last lines to:

$connection = mysqli_connect($mysql_hostname, $mysql_user, $mysql_password) or die("Mate you fucked something up!");

mysqli_select_db($connection, $mysql_database) or die("Mate you fucked something up!");

(Added the "i" after "mysql" / also switched parameters on db-selection)

More information on MySQLi: http://www.w3schools.com/php/php_ref_mysqli.asp

Sebastian G. Marinescu
  • 2,374
  • 1
  • 22
  • 33