0

I'm new to php and was wondering if anyone could help me debug, the following error. Fatal error: Call to undefined function session_register()

It occurs as I get a user to login.

PHP

<?php
include("config.php");
session_start();
if($_SERVER["REQUEST_METHOD"] == "POST")
{
// username and password sent from Form 
$myusername=addslashes($_POST['username']); 
$mypassword=addslashes($_POST['password']); 

$sql="SELECT id FROM admin WHERE username='$myusername' and passcode='$mypassword'";
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
$active=$row['active'];
$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_user']=$myusername;

header("location: welcome.php");
}
else 
{
$error="Your Login Name or Password is invalid";
}
}
?>

Error it throws out at line 16 is

$active=$row['active'];
Sam
  • 289
  • 2
  • 5
  • 15

2 Answers2

3

If you check the php manual, you will see that it has been deprecated

How about you use the $_SESSION variable?

$_SESSION["myusername"] = $username;
BenMorel
  • 31,815
  • 47
  • 169
  • 296
Ibu
  • 41,298
  • 13
  • 73
  • 100
2

First you only select id from database, so there's no $row['active']. Change $row['active'] to $row[0]['id'].

And do not use session_register("myusername"); Use $_SESSION['myusername']=="something"

You could change your query to select id,username ... and then set $_SESSION['myusername']=$row[0]['username'];

Ofcourse this method is not good, but for a beginner it should do it;

MIIB
  • 1,858
  • 10
  • 19