Jump to content

[SOLVED] for reals i need help with selecting records from db


rockindano30

Recommended Posts

i have this web app im doing.

 

 

my login page

<body>
<div id="main_wrapper">
  <div id="header"></div>
  <div id="right_content1">
    <div class="padding">    
    	<div class="log" align="center"><!--<p style="color:#000099;"><u>Login</u></p><br />-->
        <img src="images/key.png" title="" border="0" />
	<form method="post" action="validate.php">
        <p style="color:#999999">User Name:
      	<input type="text" name="Uname" size="15" maxlength="25" style="border:1px solid #999999" /></p><br />
        <p style="color:#999999">Password:  
        <input type="password" name="Pword" size="15" maxlength="25" style="border:1px solid #999999" /></p><br />
        <input type="submit" name="submit" value="Login" />
        </form><p></p></div>
    </div>
  </div>

 

my validation of user name and password is this

  <div id="right_content1">
    <div class="padding">
      <div class="p" style="clear:both; padding-left:25px;">
		<?php 
			if(!isset($_POST["Uname"]) || !isset($_POST["Pword"]))
			die("invalid operation");
			$goback = "<p><br /><br />Please <a href=\"login.html\">go back</a> and try again.</p>";

			if(empty($_POST["Uname"])) header("Location: logerror.html");
			if(empty($_POST["Pword"]))  header("Location: logerror.html");
			$Uname = $_POST["Uname"];
			$Pword = md5(trim($_POST["Pword"]));

			if (!($db = mysql_connect('localhost','username','pass')))
			{
				print"Error: could not connect to the database.";
				exit;
			}
			mysql_select_db(users);

//this line here says that i have no records
		$query = "SELECT * FROM users WHERE Uname='{$Uname}' AND Pword='{$Pword}'";
			$result = mysql_query($query);


			if(mysql_num_rows($result)==0 )
			header("Location: logerror.html");


//				$row = @ mysql_fetch_array($result);

			session_start();
			$_SESSION["user_id"]=$row["user_id"];
			$_SESSION["ip_addr"]=$_SERVER["REMOTE_ADDR"];
			$_SESSION["Lname"]=$row["Lname"];
			$_SESSION["Fname"]=$row["Fname"];

			header("LOCATION: welcome.php");
		?>
      </div>

 

problem is that it wont get all my records and there for takes me to my logerror.php page. my query is 0.

 

any suggestions or help.

its actually adding two more characters at the end of Pword when being Querys.

but dont know why though.

 

out of error:

 

error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where Pword='22317aa1cfa38056c3d03ce831d952c6'' at line 1

 

the c6 characters

No

 

Here is your query

 

$query = "SELECT * FROM users WHERE Uname='{$Uname}' AND Pword='{$Pword}'";

 

 

The error is

 

error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'where Pword='22317aa1cfa38056c3d03ce831d952c6'' at line 1

 

You have no WHERE in front of Pword, you have AND.  That means that error is from another SQL query.

You don't need the "{ }" in the query.

 

Change:

<?php
$query = "SELECT * FROM users WHERE Uname='{$Uname}' AND Pword='{$Pword}'";
$result = mysql_query($query);
?>

to

<?php
$query = "SELECT * FROM users WHERE Uname='$Uname' AND Pword='$Pword'";
$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());
?>

 

And report back what it says.

 

Ken

      <div class="p" style="clear:both; padding-left:25px;">
		<?php 
			if(!isset($_POST["Uname"]) || !isset($_POST["Pword"]))
			die("invalid operation");
			$goback = "<p><br /><br />Please <a href=\"login.html\">go back</a> and try again.</p>";

			if(empty($_POST["Uname"])) header("Location: logerror.html");
			if(empty($_POST["Pword"]))  header("Location: logerror.html");
			$Uname = $_POST["Uname"];
			$Pword = md5(trim($_POST["Pword"]));

			if (!($db = mysql_connect('localhost','user','pass')))
			{
				print"Error: could not connect to the database.";
				exit;
			}
			mysql_select_db(db_name);

			$query = "SELECT * FROM users WHERE Uname='$Uname' AND Pword='$Pword'";
			$result = mysql_query($query) or die("Problem with the query: $query<br>" . mysql_error());

          

           /////////////this is where it dies/////////////////////////////
			if(mysql_num_rows($result)==0 )
			die('error' .mysql_error());

			$row = @ mysql_fetch_array($result);

			session_start();
			$_SESSION["user_id"]=$row["user_id"];
			$_SESSION["ip_addr"]=$_SERVER["REMOTE_ADDR"];
			$_SESSION["Lname"]=$row["Lname"];
			$_SESSION["Fname"]=$row["Fname"];

			header("LOCATION: welcome.php");
		?>
      </div>

but you know if i use the mysql client and type in the sql syntax

 

select * from users where Uname='user1' and Pword='user1';

 

it says that there are 0 records in db.

 

but if i type in

select * from users where Uname='user1';

 

displays my record.

 

and if i type in select * from users where Pword='user1';

0 records????????

That's because none of your Pwords would be 'user1' in the DB.  You are using MD5 encryption.

 

What is the fieldlength and type for Pword in your DB?

 

but you know if i use the mysql client and type in the sql syntax

 

select * from users where Uname='user1' and Pword='user1';

 

it says that there are 0 records in db.

 

but if i type in

select * from users where Uname='user1';

 

displays my record.

 

and if i type in select * from users where Pword='user1';

0 records????????

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.