Jump to content

[SOLVED] Help needed with user check


pmiller624

Recommended Posts

Hi, im new here and also somewhat new to php, though i do know java and a little c++

anyways im trying to make a user check all it does it check if the given user, pass, and ip are correct

 

I can only get it to work with just using user, pass but when i try to and ip and always comes up as false

heres what I have

<?php
$host="localhost"; // Host name
$username="****"; // Mysql username
$password="*****"; // Mysql password
$db_name="*****"; // Database name
$tbl_name="user"; // Table name

// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("null");
mysql_select_db("$db_name")or die("null");

// username and password sent from form
$myusername=$_GET['u'];
$mypassword=$_GET['p'];
$myip=$_GET['i'];

// 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);
$mypassword = stripslashes($myip);
$myusername = mysql_real_escape_string($myip);

$sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword' and password='$myip'";
$result=mysql_query($sql);
$num_rows = mysql_num_rows($result);

if($num_rows > 0) {
echo 'true';
} else {
echo 'false';
}
?>

I call it with something like

http://website.com/check.php?u=bob&p=123&i=111.111.1.11

 

does anyone know why it always comes up as false

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/138348-solved-help-needed-with-user-check/
Share on other sites

Your setting $myusername to $myip and same with $mypassword, look:

 

$mypassword = stripslashes($myip);
$myusername = mysql_real_escape_string($myip);

 

Then in your query your checking if password is equal to myip.

 

password='$myip'";

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.