Current location: Hot Scripts Forums » Programming Languages » PHP » need a help to correct php search code


need a help to correct php search code

Reply
  #1 (permalink)  
Old 01-08-12, 10:02 AM
gayashan1 gayashan1 is offline
New Member
 
Join Date: Jan 2012
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
need a help to correct php search code

There is something wrong in this scrict. this doest echo the error mas " NO such a login detail exists" pls help me to find why is that ? (if query exist it shows results )

<?php
session_start();


if(!isset($_SESSION['SESS_LOGIN']) || $_SESSION['SESS_TYPE'] !='admin')// if session variable "login" does not exist.
{


header("location:searchuser.php"); // Re-direct to login-form.php

}
else
{
include("config.php");

$login = mysql_real_escape_string($_POST['login']);
$type = mysql_real_escape_string($_POST['type']);


$sql_select_login =mysql_query("SELECT * FROM members WHERE login = '$login'") or die(mysql_error()); //select by login

///////////////////// SELECT (VIEW) ////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////////


//$count_login = mysql_num_rows($sql_select_login);
$count_login = mysql_query("SELECT COUNT(login) FROM members WHERE login='$login'") or die(mysql_error());

if($count_login > 0)
{
while($row_select_login = mysql_fetch_array($sql_select_login)) {
$login_selected = $row_select_login["login"];
$password_selected = $row_select_login["password"];
$type_selected = $row_select_login["type"];

echo "$password_selected";
echo "$login_selected";
echo "$type_selected"; }

//echo "<font color=red> Duplicate Entry. Please Verify login</font>";
}
else
{
echo "<font color=red> NO such a login detail exists</font>";

}

mysql_close();

//include("searchuser.php");

}

?>
Reply With Quote
  #2 (permalink)  
Old 01-10-12, 05:54 AM
alxkls alxkls is offline
Newbie Coder
 
Join Date: Nov 2011
Posts: 98
Thanks: 0
Thanked 9 Times in 9 Posts
the problem is that mysql_query() executes the query but it alone does not return what you are looking for. so even if the query itself returns 1 or more, $count login itself does not equal 1. so let's go to the next line:
Code:
if($count_login > 0)
this is where it all fails. you need the function mysql_num_rows(). or in other words replace the existing condition with
Code:
if(mysql_num_rows($count_login)>0)
and that is of course your logic is correct. what i prefer myself is to store the query in a variable outside the functions and echo out the variable and test the query alone.


on a side note-mysql_close()-there is no point in using it. get rid of it.
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to write 'elegant' code in php? aditya2071990 PHP 7 08-05-08 06:55 AM
Executing PHP code from SQL? FuzzyLogik PHP 4 01-21-07 10:53 PM
Zip Code search range errors Merovingian PHP 2 02-09-06 03:33 PM


All times are GMT -5. The time now is 08:59 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.