Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
This is first time I am trying to do a simple PHP & MySql login but am getting 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\login_form\dbConfig.php on line 11

and what is the difference between mysql and mysqli ?

here is my login.php code and dbConfig.php code respectively:
login.php
XML
<?php include "dbConfig.php";

$msg = "";
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    $name = $_POST["name"];
    $password = md5($_POST["password"]);
     if ($name == '' || $password == '') {
        $msg = "You must enter all fields";
    } else {
        $sql = "SELECT * FROM members WHERE name = '$name' AND password = '$password'";
        $query = mysql_query($sql);

        if ($query === false) {
            echo "Could not successfully run query ($sql) from DB: " . mysql_error();
            exit;
        }

        if (mysql_num_rows($query) > 0) {

            header('Location: www.google.com');
            exit;
        }

        $msg = "Username and password do not match";
    }
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>discussdesk.com - Login form in PHP mysql</title>
<meta name="description" content=""/>
<meta name="keywords" content=""/>
<link href="style.css" rel="stylesheet" type="text/css">

</head>
<body>

    <form name="frmregister"action="<?= $_SERVER['PHP_SELF'] ?>" method="post" >
        <table class="form" border="0">

            <tr>
            <td></td>
                <td style="color:red;">
                <?php echo $msg; ?></td>
            </tr>

            <tr>
                <th><label for="name"><strong>Name:</strong></label></th>
                <td><input class="inp-text" name="name" id="name" type="text" size="30" /></td>
            </tr>
            <tr>
                <th><label for="name"><strong>Password:</strong></label></th>
                <td><input class="inp-text" name="password" id="password" type="password" size="30" /></td>
            </tr>
            <tr>
            <td></td>
                <td class="submit-button-right">
                <input class="send_btn" type="submit" value="Submit" alt="Submit" title="Submit" />

                <input class="send_btn" type="reset" value="Reset" alt="Reset" title="Reset" /></td>

            </tr>
        </table>
    </form>

<div style="line-height: 30px; margin-left: 307px;"><b>Name:</b> discussdesk <br/>  <b>Password:</b> discussdesk</div>
<div style="line-height: 30px; margin-left: 207px;">For More Info: <a href="http://www.discussdesk.com">Visit our Website</a></div>

</body>
</html>



dbConfig.php

PHP
<?php

define ("DB_HOST", "localhost"); // set database host

define ("DB_USER", "root"); // set database user

define ("DB_PASS",""); // set database password

define ("DB_NAME","innodb"); // set database name

$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die("Couldn't make connection.");

$db = mysql_select_db(DB_NAME, $link) or die("Couldn't select database");

?>
Posted
Updated 29-Jan-18 15:34pm

Did you search Google for this? And Error message clearly tells you about the issue. Check these threads for details
The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead[^]
Deprecated: mysql_connect()[^]
 
Share this answer
 
I din't read your code - it's irrelevant.
Read the error message carefully! It tells you use an old MySQL driver extension of PHP and tells you should use the new one as the old may be removed in future PHP distributions...
The only different is that you should write mysqli_connect instead of mysql_connect, and the same for other methods...
http://php.net/manual/en/book.mysqli.php[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900