This question already has an answer here:
I am an amateur programmer. I have a php code that handles the login of my site, which has functions that have been deprecated in php 7.x.x. The code was made for php 5 etc.
Since MySQL has been removed for php 7 I tried getting the code work by working around it by replacing it with mysqli etc but getting the error: Parse error: syntax error, unexpected '{', expecting ':' in /loginscript.php on line 33
The original code is:
<?php session_start();
require '../include/sqlconn.php';
$user = $_POST['user_name'];
$password = $_POST['password'];
$_SESSION['user'] =$user;
$sqlsel ="select * from user where user_name='$user' and password='$password'";
$result=mysql_query($sqlsel);
$n= mysql_num_rows($result);
if ($n >0)
{
$auth = 1;
$_SESSION['auth'] = $auth;
while ($row =mysql_fetch_assoc($result))
{
extract($row);
$_SESSION['right'] =$right;
$_SESSION['location'] =$location;
if ($_SESSION['right'] == "Administrator")
{
header("location:../setup/main.php");
}
if ($_SESSION['right'] == "User")
{
header("location:../user/main.php");
}
}
}
else
{
header("location:logout.php");
}
?>
What I tried to do (which failed) is:
<?php session_start();
require '../include/sqlconn.php';
$user = $_POST['user_name'];
$password = $_POST['password'];
$_SESSION['user'] =$user;
$con = mysqli_connect("f3.server.com", "2069590_test", "pass");
mysqli_select_db($con, "2069590_test");
$result=mysqli_query($con, "select * from user where user_name='$user' and password='$password'") or die(mysqli_error($con));
if (mysqli_num_rows($result)>0):
{
$auth = 1;
$_SESSION['auth'] = $auth;
while ($row =mysql_fetch_assoc($result))
{
extract($row);
$_SESSION['right'] =$right;
$_SESSION['location'] =$location;
if ($_SESSION['right'] == "Administrator")
{
header("location:../setup/main.php");
}
if ($_SESSION['right'] == "User")
{
header("location:../user/main.php");
}
}
}
else
{
header("location:logout.php");
}
?>
Please help me get this code work on php 7. Thanks
</div>