Page 1 of 1

Row Call Results in No UID

Posted: Wed May 13, 2009 1:03 pm
by ProductManager
I am trying to get a UID stated back based on a query (line 23). The query itself returns a value when I run it in MySQL. If I echo the $sql, it is returning formatted correctly. The row for UID (from line 34) is coming back with an empty result in the page, however. The echo for $myusername is working fine. Any thoughts would be greatly appreciated.

Code: Select all

<?php
session_start();
$host="localhost"; // Host name 
$username="user"; // Mysql username 
$password="pass"; // Mysql password 
$db_name="dbname"; // Database name 
$tbl_name="luser"; // Table name
 
// Connect to server and select databse.
mysql_connect("$host", "$username", "$password")or die("cannot connect"); 
mysql_select_db("laborchamp")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 user='$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, $myUID and redirect to file "login_success.php"
$_SESSION['myusername']=$myusername;
$_SESSION['mypassword']=$mypassword;
session_register("myusername");
echo $myusername;
echo $row['UID'];
echo $sql;
//header("location:Login_Success.php");
}
else {
echo "Wrong Username or Password";
}

Re: Row Call Results in No UID

Posted: Wed May 13, 2009 2:33 pm
by crazycoders
Where do you actually use mysql_fetch_assoc in your code? i see $row['UID'] but i never see something like:

Code: Select all

 
$row = mysql_fetch_assoc($result);
 

Re: Row Call Results in No UID

Posted: Thu May 14, 2009 6:47 am
by ProductManager
Thanks - silly mistake.