Fatal error: Uncaught Error: Call to undefined function mysql_connect() in C:\xampp\htdocs\insurance\login.php:15 Stack trace: #0 {main} thrown in C:\xampp\htdocs\insurance\login.php on line 15
Code (PHP)
<head>
<meta http-equiv=Content-Type content="text/html; charset=utf-8">
</head>
<?php
//Start session
session_start();
//Array to store validation errors
$errmsg_arr = array();
//Validation error flag
$errflag = false;
//Connect to mysql server
$link = mysql_connect('localhost','root',"...");
mysql_set_charset('utf8',$link);
if(!$link) {
die('Failed to connect to server: ' . mysql_error());
}
//Select database
$db = mysql_select_db('ดาต้าเบส', $link);
if(!$db) {
die("Unable to select database");
}
//Function to sanitize values received from the form. Prevents SQL injection
function clean($str) {
$str = @trim($str);
if(get_magic_quotes_gpc()) {
$str = stripslashes($str);
}
return mysql_real_escape_string($str);
}
//Sanitize the POST values
$login = clean($_POST['username']);
$password = clean($_POST['password']);
//Input Validations
if($login == '') {
$errmsg_arr[] = 'Username missing';
$errflag = true;
}
if($password == '') {
$errmsg_arr[] = 'Password missing';
$errflag = true;
}
//If there are input validations, redirect back to the login form
if($errflag) {
$_SESSION['ERRMSG_ARR'] = $errmsg_arr;
session_write_close();
header("location: index.php");
exit();
}
//Create query
$qry="SELECT * FROM User_insurance WHERE UserName='$login' AND UserPassword='$password'";
$result=mysql_query($qry);
mysql_query("SET NAMES UTF8");
mysql_query("SET character_set_results=utf8");
mysql_query("SET character_set_client=utf8");
mysql_query("SET character_set_connection=utf8");
//Check whether the query was successful or not
if($result) {
if(mysql_num_rows($result) > 0) {
//Login Successful
session_regenerate_id();
$member = mysql_fetch_assoc($result);
$_SESSION['SESS_MEMBER_ID'] = $member['User_ID'];
$_SESSION['SESS_FIRST_NAME'] = $member['FisrtName'];
$_SESSION['SESS_UserLevel'] = $member['UserLevel'];
$_SESSION['SESS_Position'] = $member['Position'];
//$_SESSION['SESS_PRO_PIC'] = $member['profImage'];
session_write_close();
header("location: main/index.php");
exit();
}else {
//Login failed
header("location: index.php");
exit();
}
}else {
die("Query failed");
}
?>