Jump to content


Photo

Help Needed with script


  • Please log in to reply
3 replies to this topic

#1 dr_overload

dr_overload
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 May 2006 - 11:04 PM

I'm a newbie and have tried to work out a script but just simply cant manage it. Any chance someone can help me?

Basically all I want to do is have a script that compares the values of two mysql fields, if the are the same, print the value of the third field, else print the value of fourth field.

I got the it working from without connecting to the database and giving the values in the script
ie
<?php
$a=2;
$b=2;
$c=5;
$d=0;
if ( $a == $b ) {
echo "$c";
} else {
echo "$d";
}
?>
But when i try to replace the values with what is in the database it doesnt work - I guess my script for comparing the mysql field values is not working properly.

Any help would be most appreciate.

Cheers


#2 litebearer

litebearer
  • Members
  • PipPipPip
  • Advanced Member
  • 2,357 posts
  • Locationwhite lake michigan

Posted 27 May 2006 - 11:10 PM

Are you limiting your sql query to specific records, or are you checking every record?

all the brothers were valiant!

[br][br]The truely intelligent people are not those who create the dots; rather they are they ones with the ability to connect the dots into a coherent picture

#3 dr_overload

dr_overload
  • New Members
  • Pip
  • Newbie
  • 3 posts

Posted 27 May 2006 - 11:15 PM

[!--quoteo(post=377678:date=May 27 2006, 06:10 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 27 2006, 06:10 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Are you limiting your sql query to specific records, or are you checking every record?
[/quote]

I have a login script and it will take the entry from the row of the inputted username

#4 Ferenc

Ferenc
  • Members
  • PipPipPip
  • Advanced Member
  • 94 posts

Posted 28 May 2006 - 04:30 AM

just count the rows returned by the query. if the user and password match, you will have a count of one

$sql = mysql_query("SELECT * FROM user_table WHERE user_name_table = $posted_username AND password = $posted_password") or die(mysql_error());

if(mysql_num_rows($sql) == '1'){
  // user was in database
}else{
  // user was not in database
}

Everything you want to know is here.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users