Jump to content

Archived

This topic is now archived and is closed to further replies.

dr_overload

Help Needed with script

Recommended Posts

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

Share this post


Link to post
Share on other sites
Are you limiting your sql query to specific records, or are you checking every record?

Share this post


Link to post
Share on other sites
[!--quoteo(post=377678:date=May 27 2006, 06:10 PM:name=litebearer)--][div class=\'quotetop\']QUOTE(litebearer @ May 27 2006, 06:10 PM) [snapback]377678[/snapback][/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

Share this post


Link to post
Share on other sites
just count the rows returned by the query. if the user and password match, you will have a count of one

[code]$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
}[/code]

Share this post


Link to post
Share on other sites

×

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.