Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SELECT doesn't work the first time but does the second?

Status
Not open for further replies.

CliffLandin

Programmer
Nov 14, 2004
81
US
I am fairly new to mysql but have been using small snippets here and there while writing php pages. I have a site that I am creating that has a simple sign in page and a few other mysql uses.

The problem that I am having is that when I first go to the page and try to log on using my username and password it doesn't work. If I try again it works just fine.

I go to the next page where I create a trip number based on the last trip number and then I display it. It doesn't display it unless I refresh the page.

here is a sample of how I am checking the password with the user name:

<?php
session_start();
header("Cache-control: private");

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

$link = mysql_connect("$something", "$someother", "$someone");
if (!$link) {
die("Could not connect: " . mysql_error());
}
mysql_select_db("dbName", $link)
or die("Could not select database");

$query = "SELECT password FROM table WHERE userName='$user'";
$result = mysql_query($query);
$row = mysql_fetch_row($result);

$pass2 = $row[0];

mysql_close($link);

if (($user=="") or ($pass==""))
header("Location: elseif ($pass<>$pass2)
header("Location: else{
$_SESSION['user'] = $user;
header("Location: }
?>

It works fine on the second go 'round. The simple error checking works fine. I am sure that it is something fairly simple. As I said before, I am new to mysql.
Any help is appreciated.
Thanks,

When in doubt, go flat out!

 
Okay, since I was not offered any help here, I was forced to figure it out on my own. If any of you are curious, for some reason the session ID was being passed to the sign-in page through the url. Changing the link to the whole name rather than just the page did the trick. I.E. changing <a href="something.php"> to <a href="somepage.com/something.php">. This seems to have done the trick.

When in doubt, go flat out!

 
that is a very strange solution, but than again, this is a strange problem...was there anything in the logs previous to your solution to indicate a problem?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top