Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 03-15-2005, 12:43 PM Lil problemo...
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Code:
$username = $row['username'];
$password = $row['password'];
$id = $row['id'];

if ($num==0) {
echo ("The database contains no record of your user or your password is incorrect."); 
} else {
setcookie("XingName", "$username");
setcookie("XingID", "$id");
mysql_close();
echo("<meta http-equiv=\"refresh\" content=\"0;URL=./?q=\">"); } 

} else { ?>

<form name="login" action="" method="post">
  <p>
    <input name="user" type="text" id="user">
</p>
  <p>
    <input name="pass" type="password" id="pass" value="">
</p>
  <p>
    <input type="submit" name="login" value="Submit">
    <input type="reset" name="Reset" value="Reset">
</p>
</form>

<? 

}

?>
^^ having a small problem with that code, when the user logs in.. it says "The database contains no record of your user or your password is incorrect."

The only time it says that is when the user does not exist or the password / username is incorrect... can anyone help why this is happening and not doing what its meant to?
feraira is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-15-2005, 01:08 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Where is $num coming from? You are checking if( $num == 0 ), but your code does not show where $num gains its value. Also, you have two else clauses for only one if(), so there is clearly some more code preceeding this segment in the file. Post the whole file so we can get a better idea of what is going on.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-15-2005, 01:51 PM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
thats the entire file, excluding the db connection... $num doesnt represent anything, i dont know what to put... thought it was

"$num=mysql_num_rows($result);" but it doesnt work
feraira is offline
Reply With Quote
View Public Profile
 
Old 03-15-2005, 02:10 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
For that matter, where does $row come from? I'm guessing there is a database query happening somewhere, but that's not shown in your post.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 03-15-2005, 02:20 PM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
Code:
<?

if (isset($_POST['login'])) {

$username = $_POST["user"];
$password = $_POST["pass"];

mysql_connect("localhost", "user", "password") or die( "Unable to connect to database");
@mysql_select_db("db") or die( "Unable to select database");

$query="SELECT * FROM users WHERE user='$username' AND pass = '$password'";
$result=mysql_query($query);

$username = $row['username'];
$password = $row['password'];
$id = $row['id'];

if ($num==0) {
echo ("The database contains no record of your user or your password is incorrect."); 
} else {
setcookie("XingName", "$username");
setcookie("XingID", "$id");
mysql_close();
echo("<meta http-equiv=\"refresh\" content=\"0;URL=./?q=\">"); } 

} else { ?>

<form name="login" action="" method="post">
  <p>
    <input name="user" type="text" id="user">
</p>
  <p>
    <input name="pass" type="password" id="pass" value="">
</p>
  <p>
    <input type="submit" name="login" value="Submit">
    <input type="reset" name="Reset" value="Reset">
</p>
</form>

<? 

}

?>
feraira is offline
Reply With Quote
View Public Profile
 
Old 03-15-2005, 02:36 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
You are never calling mysql_fetch_array($result) to have $row assigned. I honestly don't know how your script is ever working. I don't know how you are not getting a syntax error with the additional else statement.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Old 03-15-2005, 05:00 PM
feraira's Avatar
BeTheBand!

Posts: 350
Trades: 0
could you help then?
feraira is offline
Reply With Quote
View Public Profile
 
Old 03-15-2005, 07:35 PM
Republikin's Avatar
Defies a Status

Posts: 3,189
Trades: 3
Kyrnt, if you look again you will see that the second else statement is for the first if. It is opened properly.

Try this...

PHP Code:
<?

if (isset($_POST['login'])) {

$username $_POST["user"];
$password $_POST["pass"];

mysql_connect("localhost""user""password") or die( "Unable to connect to database");
@
mysql_select_db("db") or die( "Unable to select database");

$query="SELECT * FROM users WHERE user='$username' AND pass = '$password'";
$result=mysql_query($query);
$row mysql_fetch_assoc($result);

$username $row['username'];
$password $row['password'];
$id $row['id'];

if (
$id==0) {
echo (
"The database contains no record of your user or your password is incorrect."); 
} else {
setcookie("XingName""$username");
setcookie("XingID""$id");
mysql_close();
echo(
"<meta http-equiv=\"refresh\" content=\"0;URL=./?q=\">"); } 

} else { 
?>

<form name="login" action="" method="post">
  <p>
    <input name="user" type="text" id="user">
</p>
  <p>
    <input name="pass" type="password" id="pass" value="">
</p>
  <p>
    <input type="submit" name="login" value="Submit">
    <input type="reset" name="Reset" value="Reset">
</p>
</form>

<? 

}

?>
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Republikin is offline
Reply With Quote
View Public Profile
 
Old 03-15-2005, 07:38 PM
Kyrnt's Avatar
The Post-Mod Years

Posts: 2,536
Location: Western Maryland
Trades: 0
Quote:
Originally Posted by cptnwinky
Kyrnt, if you look again you will see that the second else statement is for the first if. It is opened properly.

Cptn, Aye, I see that in the new, more complete code. But it was missing in the original posting. Hopefully your listing will solve the issue.

Thanks.
__________________
—Kyrnt
Kyrnt is offline
Reply With Quote
View Public Profile Visit Kyrnt's homepage!
 
Reply     « Reply to Lil problemo...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.28142 seconds with 12 queries