SA-MP Forums Archive
MySQL UCP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: MySQL UCP (/showthread.php?tid=603627)



MySQL UCP - Melktert - 25.03.2016

Hello, So I basically, I took another Cops and Robbers script's UCP (California Cops and Robbers) and thought that I would use it for my Cops and Robbers server (the CCNR script was further developed from the script I'm using). So here is the default "check.php" that checks the login.

Код:
 <?php
	session_start();
	include "koneksi.php";
	if(isset($_SESSION['playername']))
	{
		go('index.php', 'You already logged in.');
	}
	if(!isset($_POST['username'], $_POST['password']))
	{
		go('index.php', 'Please fillout all required forms.');
	}
	else
	{
		$query = $koneksi->prepare("SELECT `level`,`name` from `player` where `name` = ? and `password` = ?");
		$query->execute(array($_POST['username'], strtoupper(hash("whirlpool", $_POST['password']))));
		if($query->rowCount() > 0)
		{
			$data = $query->fetch();
			go('index.php', 'Succesfully logged in.');
			$_SESSION['playername'] = $data['name'];
			$_SESSION['playerlevel'] = $data['level'];
		}
		else
		{
			go('index.php', 'Wrong username or password.');
		}
	}
And here I modified it because the rows had different names of the script I'm using, Then it looks like this. But then I keep getting "Wrong username or password"

Код:
<?php
	session_start();
	include "koneksi.php";
	if(isset($_SESSION['playername']))
	{
		go('index.php', 'You already logged in.');
	}
	if(!isset($_POST['username'], $_POST['password']))
	{
		go('index.php', 'Please fillout all required forms.');
	}
	else
	{
		$query = $koneksi->prepare("SELECT `playerLevel`,`playerName` from `playerdata` where `name` = ? and `password` = ?");
		$query->execute(array($_POST['username'], strtoupper(hash("whirlpool", $_POST['password']))));
		if($query->rowCount() > 0)
		{
			$data = $query->fetch();
			go('index.php', 'Succesfully logged in.');
			$_SESSION['playername'] = $data['name'];
			$_SESSION['playerlevel'] = $data['level'];
		}
		else
		{
			go('index.php', 'Wrong username or password.');
		}
	}



Re: MySQL UCP - Melktert - 26.03.2016

Bump


Re: MySQL UCP - buburuzu19 - 26.03.2016

Try this code:

PHP код:
<?php
    session_start
();
    include 
"koneksi.php";
    
    if(isset(
$_SESSION['playername']))
    {
        
go('index.php''You already logged in.');
    }
    if(!isset(
$_POST['username'], $_POST['password']))
    {
        
go('index.php''Please fillout all required forms.');
    }
    else
    {
        
$username mysql_real_escape_string($_POST['username']);
        
$password mysql_real_escape_string($_POST['password']);
        
        
$hashedpw strtoupper(hash("whirlpool"$_POST['password']));
        
        
$check get_row("SELECT `playerLevel`,`playerName` from `playerdata` where `name` = '$username' and password = '$hashedpw'");
        if(isset(
$check['playerLevel']))
        {
            
go('index.php''Succesfully logged in.');
            
            
$_SESSION['playername'] = $check['name'];
            
$_SESSION['playerlevel'] = $check['level'];
        }
        else
        {
            
go('index.php''Wrong username or password.');
        }
    }
    
?>



Re: MySQL UCP - Melktert - 26.03.2016

I get this error when logging in, doesn't show "Wrong username or password."

Код:
( ! ) Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in G:\wamp\www\check.php on line 15
Call Stack
#	Time	Memory	Function	Location
1	0.0557	251296	{main}( )	..\check.php:0
2	0.2266	262832	mysql_real_escape_string ( )	..\check.php:15

( ! ) Fatal error: Call to undefined function get_row() in G:\wamp\www\check.php on line 20
Call Stack
#	Time	Memory	Function	Location
1	0.0557	251296	{main}( )	..\check.php:0



Re: MySQL UCP - buburuzu19 - 26.03.2016

Quote:
Originally Posted by Melktert
Посмотреть сообщение
I get this error when logging in, doesn't show "Wrong username or password."

Код:
( ! ) Deprecated: mysql_real_escape_string(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in G:\wamp\www\check.php on line 15
Call Stack
#	Time	Memory	Function	Location
1	0.0557	251296	{main}( )	..\check.php:0
2	0.2266	262832	mysql_real_escape_string ( )	..\check.php:15

( ! ) Fatal error: Call to undefined function get_row() in G:\wamp\www\check.php on line 20
Call Stack
#	Time	Memory	Function	Location
1	0.0557	251296	{main}( )	..\check.php:0
Replace this thing

PHP код:
        $username mysql_real_escape_string($_POST['username']);
        
$password mysql_real_escape_string($_POST['password']); 
with this one

PHP код:
$username $_POST['username'];
 
$password $_POST['password']; 
For get_row() error, put this thing somewhere after the opening <?php thing at the top



PHP код:
function get_row($q)
{
     
$pq mysql_query($q);
     if(
$pq === FALSE) {
    die(
mysql_error()); // better error handling
}
     
     
$p mysql_fetch_array($pq); // fetching the array
     
return $p;




Re: MySQL UCP - Melktert - 26.03.2016

Код:
( ! ) Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in G:\wamp\www\check.php on line 5
Call Stack
#	Time	Memory	Function	Location
1	0.0020	254024	{main}( )	..\check.php:0
2	0.0205	265264	get_row( )	..\check.php:32
3	0.0205	265312	mysql_query ( )	..\check.php:5
No database selected



Re: MySQL UCP - buburuzu19 - 26.03.2016

Quote:
Originally Posted by Melktert
Посмотреть сообщение
Код:
( ! ) Deprecated: mysql_query(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in G:\wamp\www\check.php on line 5
Call Stack
#	Time	Memory	Function	Location
1	0.0020	254024	{main}( )	..\check.php:0
2	0.0205	265264	get_row( )	..\check.php:32
3	0.0205	265312	mysql_query ( )	..\check.php:5
No database selected
Show me the full page of "koneksi.php"


Re: MySQL UCP - X337 - 26.03.2016

mysql_ function is deprecated and afaik, already removed on PHP 7.
You can hide that error by adding
error_reporting(0); or error_reporting(E_ALL &~ E_DEPRECATED);
at top of your script.


Re: MySQL UCP - buburuzu19 - 26.03.2016

Quote:
Originally Posted by X337
Посмотреть сообщение
mysql_ function is deprecated and afaik, already removed on PHP 7.
You can hide that error by adding
error_reporting(0); or error_reporting(E_ALL &~ E_DEPRECATED);
at top of your script.
He could do this but is not really recommended for using. Best way for him is fixing that error.


Re: MySQL UCP - X337 - 26.03.2016

Quote:
Originally Posted by buburuzu19
Посмотреть сообщение
He could do this but is not really recommended for using. Best way for him is fixing that error.
The only way to fix that error, is just using mysqli or PDO.
So there's no way to fix that error, except using mysqli, PDO, or hide deprecated warning.