SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    May 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help needed with PHP My Sql code

    Can anyone tell me why this ph code will not return anything when the value of $dbaccno is grater than 999?



    //Retrive Members account information from accinfo table
    $query = mysql_query("Select * FROM accinfo WHERE AccNumber ='$dbAccNumber' LIMIT 3000");
    $numrows = mysql_num_rows($query);
    if($numrows >0)
    {
    while ($row = mysql_fetch_assoc($query))
    {
    $dbname=$row['Name'];
    $dbaccno=$row['AccNumber'];
    $dbAccbal=$row['AccountBalance'];
    $dbpay=$row['Lastpaid'];
    $dbpaydate=$row['Lastdatepaid'];
    $dbreading=$row['reading'];
    $dbreaddate=$row['readingdate'];
    $dbprvread=$row['prevreading'];
    $dbusage=$row['usage'];

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Welcome to the SP forums
    Can anyone tell me why this ph code will not return anything when the value of $dbaccno is grater than 999?
    Because there are no account numbers greater than 999?

    You could do an echo of $numrows to see if anything is returned. And also an echo of $dbAccNumber to see if it contains the value you expect it to have.

  3. #3
    SitePoint Member
    Join Date
    May 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have acc number to 2780, can get variable values for any account up to # 999, above get nothing with no error message. Not sure what LIMIT does.

    should i be using mysql_fetch_array($query)) instead of mysql_fetch_assoc($query))?

    thanks fory your reply

  4. #4
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by rwdno2 View Post
    Not sure what LIMIT does.
    It limits the number of rows returned by the query to a max of 3000 rows.
    should i be using mysql_fetch_array($query)) instead of mysql_fetch_assoc($query))?
    No.

    Did you try to echo the two variables as I asked you to? Please post the results here.

  5. #5
    SitePoint Member
    Join Date
    May 2010
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    20950Cannot get your information at this time

    9991THIS INFORMATION DOES NOT REFLECT ANY TRANACTIONS AFTER 14TH OF MAY

    2095 & 999 are echo of $dbAccNumber
    0 & 1 are echo of $numrows

    following is the entire php file

    Code PHP:
    <?php
     
    //.$_SESSION ['username'].
     
    //set variable values = to user login form entries
    $username=$_POST['username'];
    $number=$_POST['accnumber'];
    $password=strip_tags($_POST['password']);
    	//encrypt password
    $password=md5($password);
     
     
    //require entery in all fields
    if ($username&&$password&&$number)
    {
     //connect to database
     $connect = mysql_connect("localhost","rwd_job","******") or die("Couldn't connect");
     mysql_select_db("rwdnotwo_accinfo") or die ("Couldn't find database");
     
     //Retrive Members user name & password & account number from users table
     $query = mysql_query("Select * FROM users WHERE password ='$password' AND username='$username'");
     $numrows = mysql_num_rows($query);
    	if($numrows >0)
    	{
    		while ($row = mysql_fetch_assoc($query))
    		{
    		$dbusername=$row['username'];
    		$dbpassword=$row['password'];
    		$dbAccNumber=$row['AccNumber'];
    		$dbemail=$row['email_address'];
    		}
     
    		//check to see if they match
    		if($username==$dbusername)
    		{
    			if($number==$dbAccNumber)
    			{
                  if($password==$dbpassword)
    			 {
     
    			   //Retrive Members account information from accinfo table
    			   echo $dbAccNumber;
    				$query = mysql_query("Select * FROM accinfo WHERE AccNumber ='$dbAccNumber' LIMIT 3000");
    				$numrows = mysql_num_rows($query);
    				echo $numrows;
    				if($numrows >0)
    				{
    					while ($row = mysql_fetch_assoc($query))
    					{
    					$dbname=$row['Name'];
    					$dbaccno=$row['AccNumber'];
    					$dbAccbal=$row['AccountBalance'];
    					$dbpay=$row['Lastpaid'];
    					$dbpaydate=$row['Lastdatepaid'];
    					$dbreading=$row['reading'];
    					$dbreaddate=$row['readingdate'];
    					$dbprvread=$row['prevreading'];
    					$dbusage=$row['usage'];
     
    					}
    						//Print account information to screen
    						echo "THIS INFORMATION DOES NOT REFLECT ANY TRANACTIONS AFTER 14TH OF MAY";
    						echo "<br>";
                            echo "<br>";
     
    						echo "Account Name         ";
    						echo $dbname;
    						echo "<br>";
     
    						echo "Account Balance "        ;
    						echo $dbAccbal;
    						echo "<br>";
     
    						echo "Last Payment "       ;
    						echo $dbpay;
    						echo"   Date  "; 
    						echo$dbpaydate;
    						echo "<br>";
     
    						echo " Latest  Reading "      ;
    						echo $dbreading;
    						echo "00 Date "      ;
    						echo $dbreaddate;
    						echo "<br>";
     
    						echo "Previous Reading "      ;
    						echo $dbprvread;
    						echo"00";
    						echo "<br>";
     
    						echo "Usage "      ;
    						echo $dbusage;
    						echo "<br>";
     
    			            echo "<br><a href='login.php'>Click here to return to Login</a>";
     
    				}
    				else
    				echo "Cannot get your information at this time<br><a href='accinfo.html'>Click here to return to Login</a>";
    				echo $dbAccno;
    			  }
    			  else
    			  echo "Incorrect password!<br><a href='accinfo.html'>Click here to return to Login</a>";			
    			}
    			else
    			echo "Account Number does not match username!<br><a href='accinfo.html'>Click here to return to Login</a>";
    		}
    		else
    		echo "Incorrect Username!<br><a href='accinfo.html'>Click here to return to Login</a>";		
    	}
    	else
    		echo "Please reenter your Account Number, UserName & Password <br><a href='accinfo.html'>Click here to return to Login</a>";
     }
     
    else
    	echo "Please enter your Account Number, UserName & Password  !<b r><a href='accinfo.html'>Click here to return to Login</a>";
    ?>
    Last edited by Mittineague; May 17, 2010 at 17:05. Reason: adding highlighting

  6. #6
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,500
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    So, your query returns 0 rows.
    Try to run the query manually in PHPMyAdmin, putting the account number where the variable is, and see if it returns anything.
    My guess is there aren't any rows in accinfo for that account number.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •