SA-MP Forums Archive
PHP Status show help - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: Other (https://sampforum.blast.hk/forumdisplay.php?fid=7)
+--- Forum: Everything and Nothing (https://sampforum.blast.hk/forumdisplay.php?fid=23)
+--- Thread: PHP Status show help (/showthread.php?tid=313850)



PHP Status show help - thimo - 27.01.2012

So im trying to make a PHP status show for the online player login but it always returns 0 rows anyone sees how to fix that?
PHP код:
<? 
session_start
();
if(!
session_is_registered(Name)){
header("location:Accounts.php");
}
?>

<html>
<body>
<?php
/* Change next two lines  if using online*/
$db="Censored";
$link mysql_connect('Censored''Censored''Censored');
if (! 
$link) die(mysql_error());
mysql_select_db($db $link) or die("Couldn't open $db: ".mysql_error());
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);
$result mysql_query"SELECT * FROM Users WHERE Name ='$Name' and Password='$mypassword'" )
          or die(
"SELECT Error: ".mysql_error());
$num_rows mysql_num_rows($result);
print 
"There are $num_rows records.<br>";
print 
"<table width=600 border=1>\n";
print 
"Name, admin, PosX, PosY, PosZ, Score, Male/Female/Age";
while (
$get_info mysql_fetch_row($result)){
print 
"<tr>\n";
foreach (
$get_info as $field)
print 
"\t<td>$field</td>\n";
print 
"</tr>\n";
}
print 
"</table>\n";
mysql_close($link);
?>

</body>
</html>
Thanks in advance


Re: PHP Status show help - Bumbis - 27.01.2012

I dont see variable $Name defined anywhere. I guess you might use $myusername instad of $Name in that query.


Re: PHP Status show help - thimo - 27.01.2012

Did that and it returns 0 rows


Re: PHP Status show help - royal_king - 27.01.2012

PHP код:
mysql_query"SELECT * FROM Users WHERE Name ='$Name' and Password='$mypassword'" 
          or die(
"SELECT Error: ".mysql_error()); 
No $Name value defined so use this below one


PHP код:
mysql_query"SELECT * FROM Users WHERE Name ='$myusername' and Password='$mypassword'" 
          or die(
"SELECT Error: ".mysql_error()); 
And is you're database got some values in it? (i mean information like name, etc..)

Insert some values into database for test and try, if any problem let us know.


Re: PHP Status show help - thimo - 27.01.2012

Well that aint working All i want to do is print the info of the specified player if you need my checklogin.php this is it:
PHP код:
<?php
$host
="CENSORED"// Host name 
$username="CENSORED"// Mysql username 
$password="CENSORED"// Mysql password 
$db_name="CENSORED"// Database name 
$tbl_name="CENSORED"// Table name

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);

$sql="SELECT * FROM $tbl_name WHERE Name ='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);

// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row

if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("Name");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo 
"Wrong Username or Password";
}
?>



Re: PHP Status show help - Sinner - 28.01.2012

THe code looks good, maybe you have 2 records with the same name? Try:

PHP код:
echo "We found ".$count." rows"// debug
if($count >= 1) {
    ...
} else {
    ...




Re: PHP Status show help - thimo - 28.01.2012

I now got this:
PHP код:
<? 
session_start
();
if(!
session_is_registered(Name)){
header("location:Accounts.php");
}
?>

<html>
<body>
<?php
$host
="Censored"// Host name 
$username="Censored"// Mysql username 
$password="Censored"// Mysql password 
$db_name="Censored"// Database name 
$tbl_name="Censored"// Table name

// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];

$sqlsprintf("SELECT Name, Password FROM $tbl_name WHERE Name ='$myusername'");
$result=mysql_query($sql);
while (
$row mysql_fetch_assoc($result))
{
    echo 
$row['Name'];
    echo 
$row['Password'];
}
?>

</body>
</html>
I found out that the thingy $myusername doesnt get the value from the login form so it doesnt query it with the right name...
Anyone have an idea why?


Re: PHP Status show help - Sinner - 28.01.2012

Show us your input form please


Re: PHP Status show help - thimo - 28.01.2012

Код HTML:
<table width="100" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">

<tr>

<form name="form1" method="post" action="checklogin.php">

<td>

<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">

<tr>

<td colspan="3"><strong>Player Login </strong></td>

</tr>

<tr>

<td width="50">Username</td>

<td width="1">:</td>

<td width="294"><input name="myusername" type="text" id="myusername"></td>

</tr>

<tr>

<td>Password</td>

<td>:</td>

<td><input name="mypassword" type="password" id="mypassword"></td>

</tr>

<tr>

<td>&nbsp;</td>

<td>&nbsp;</td>

<td><input type="submit" name="Submit" value="Login"></td>

</tr>

</table>

</td>

</form>

</tr>

</table>
And btw i now get these errors from checklogin.php when Username and pw are right:
Код:
Deprecated: Function session_register() is deprecated in /home/thimo/public_html/checklogin.php on line 37

Warning: session_register() [function.session-register]: Cannot send session cache limiter - headers already sent (output started at /home/thimo/public_html/checklogin.php:37) in /home/thimo/public_html/checklogin.php on line 37

Deprecated: Function session_register() is deprecated in /home/thimo/public_html/checklogin.php on line 38

Warning: Cannot modify header information - headers already sent by (output started at /home/thimo/public_html/checklogin.php:37) in /home/thimo/public_html/checklogin.php on line 39
And this is the checklogin.php
PHP код:
<?php
ini_set
('display_errors'1); // 0 = uit, 1 = aan
error_reporting(E_ALL);
$host="188.138.79.5"// Host name 
$username="johan_Mysql"// Mysql username 
$password="Thimo9"// Mysql password 
$db_name="johan_Mysql"// Database name 
$tbl_name="Users"// Table name
// Connect to server and select databse.
mysql_connect("$host""$username""$password")or die("cannot connect"); 
mysql_select_db("$db_name")or die("cannot select DB");
// username and password sent from form 
$myusername=$_POST['myusername']; 
$mypassword=$_POST['mypassword'];
// To protect MySQL injection (more detail about MySQL injection)
$myusername stripslashes($myusername);
$mypassword stripslashes($mypassword);
$myusername mysql_real_escape_string($myusername);
$mypassword mysql_real_escape_string($mypassword);
$sql="SELECT * FROM $tbl_name WHERE Name ='$myusername' and Password='$mypassword'";
$result=mysql_query($sql);
// Mysql_num_row is counting table row
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1){
// Register $myusername, $mypassword and redirect to file "login_success.php"
session_register("myusername");
session_register("mypassword"); 
header("location:login_success.php");
}
else {
echo 
"Wrong Username or Password";
}
?>



Re: PHP Status show help - Sinner - 28.01.2012

I think the reason is because you forgot to terminate your input fields ' />'

try this:
Код HTML:
<table width="100" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#CCCCCC">
	<tr>
	<form name="form1" method="post" action="checklogin.php">
		<td>
		<table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#FFFFFF">
			<tr>
				<td colspan="3"><strong>Player Login </strong></td>
			</tr>
			<tr>
				<td width="50">Username</td>
				<td width="1">:</td>
				<td width="294"><input name="myusername" type="text" id="myusername" /></td>
			</tr>
			<tr>
				<td>Password</td>
				<td>:</td>
				<td><input name="mypassword" type="password" id="mypassword" /></td>
			</tr>
			<tr>
				<td>&nbsp;</td>
				<td>&nbsp;</td>
				<td><input type="submit" name="Submit" value="Login"></td>
			</tr>
		</table>
		</td>
	</form>
	</tr>
</table>