Fatal error: function call undefined session_register ()

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

This happens when I can log in.

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"; } } ?> 

The error that it throws on line 16,

 $active=$row['active']; 
0
source share
2 answers

If you check the php manual you will see that it is out of date

How about using the $_SESSION variable?

 $_SESSION["myusername"] = $username; 
+3
source

At first you only select id from the database, so there is no $row['active'] . Change $row['active'] to $row[0]['id'] .

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

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

Of course, this method is not good, but for a beginner he should do it;

+2
source

Source: https://habr.com/ru/post/954024/


All Articles