-4

"Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\laragon\www\farmer\config\config.php:3 Stack trace: #0 C:\laragon\www\farmer\Execute\ExLogin.php(6): include() #1 {main} thrown in C:\laragon\www\farmer\config\config.php on line 3"

Here is config.php

<?php
mysql_connect("localhost", "root", "newton2010") or die(mysql_error());
mysql_select_db("farmer") or die(mysql_error());
?>

<?Php

//session_start();
$dbhost_name = "localhost";
$database = "farmer";// database name
$username = "root"; // user name
$password = "newton2010"; // password 

//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}

?>

Here is my Exlogin.php

    <?php
// Start the session
session_start();


include '../config/config.php';
include '../config/config1.php';
include '../config/connect.php';

 $UName = ($_POST["Username"]);
 $PW = ($_POST["Password"]);
  $status = "Accepted";
 $PassWord=0;
 $UserName=0;

$quer= mysql_query("SELECT * FROM customers where username='$UName' AND password='$PW' ");
while($ss = mysql_fetch_array($quer))
    {
    $UserName=$ss['username'];
    $PassWord=$ss['password'];
    $userid=$ss['customerid'];
    $name=$ss['firstnames'];
    $activate=$ss['status'];
    //$profilepicture=$ss['profilepicture'];
    //$IDBranch=$ss['IDBranch'];
    $role=$ss['role'];
    }

if($PassWord!=$PW || $UserName!=$UName || $activate!=$status ){
echo "<script>alert('You account is disabled or You have entered Incorrect UserName or Password')</script>";
echo "<script>location.href='../index.php'</script>";
}
else
{
$_SESSION["Id"]=$userid;
$_SESSION["name"]=$name;
//$_SESSION["profilepicture"]=$profilepicture;
//$_SESSION["IDBranch"]=$IDBranch;
$_SESSION["role"]=$role;

?>

<!--<script>
var person = prompt("Please enter your name", "Harry Potter");
if (person != null) {
    document.getElementById("demo").innerHTML =
    "Hello " + person + "! How are you today?";
}
</script>-->
<script>location.href='../dashboard.php'</script>"; --> 

<?php } ?>
Eray Balkanli
  • 7,306
  • 10
  • 44
  • 74
  • I guess you're running PHP 7. `mysql_connect()` doesn't exist in PHP 7 anymore. You should have a look at `mysqli_connect()` instead. – Dirk Scholten Nov 16 '18 at 13:29
  • this is telling you that mysql_* functions are not available in that server, use phpinfo() to check which version of php it is, if it is 7, then it means those functions are removed – noid Nov 16 '18 at 13:30
  • Read this may helpful to you https://stackoverflow.com/a/13825126/2893413 – Sadikhasan Nov 16 '18 at 13:37
  • try mysqli_connect method instead mysql_connect – Manoj Singh Nov 16 '18 at 13:39
  • it may help you https://stackoverflow.com/questions/34088373/call-to-undefined-function-mysql-connect-after-upgrade-to-php-7 – Manoj Singh Nov 16 '18 at 13:41
  • From [the manual](https://secure.php.net/manual/en/function.mysql-connect.php): "_Warning This extension was deprecated in PHP 5.5.0, and it was removed in PHP 7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used._" – brombeer Nov 16 '18 at 13:42

1 Answers1

0

I used the recommendation made by @sadikhasan on using fix.mysql.inc.php

Then I ran into this new error "Parse error: syntax error, unexpected '<', expecting end of file in C:\laragon\www\farmer\config\config.php on line 4"

Here is my updated config.php

    <?php
include_once('fix_mysql.inc.php');

<?php
mysql_connect("localhost", "root", "newton2010") or die(mysql_error());
mysql_select_db("farmer") or die(mysql_error());
?>

<?Php

//session_start();
$dbhost_name = "localhost";
$database = "farmer";// database name
$username = "root"; // user name
$password = "newton2010"; // password 

//////// Do not Edit below /////////
try {
$dbo = new PDO('mysql:host=localhost;dbname='.$database, $username, $password);
} catch (PDOException $e) {
print "Error!: " . $e->getMessage() . "<br/>";
die();
}

?>