Reisswolf Posted July 10, 2006 Share Posted July 10, 2006 Hi everyone,I am not exactly a PHP newbie, but nevertheless, I am unable to find my error here. Some help would be greatly appreciated.The basic structure of the code is as follows:[code]<?php$title = "My Page Title"include("header.inc");function MainFunction($user_name, $db) { if(!isset($_SESSION['login_flag']) || $_SESSION['login_flag'] == FALSE) { echo "Sorry, you are not logged in."; } // End if() else { $result = mysql_query("SELECT * FROM user_accounts_table WHERE 'user_name'='$user_name' LIMIT 1", $db) or die(mysql_error()); $table_row = mysql_fetch_array($result); echo "You are logged in as " . $user_name . ". Your details are as follows:"; echo "User ID - " . $table_row['user_id'] . "<br />"; echo "User Name - " . $table_row['user_name'] . "<br />"; echo "Password - " . $table_row['password'] . "<br />"; echo "E-Mail - " . $table_row['email'] . "<br />"; } // End else} // End MainFunction()// Call MainFunction()MainFunction($SESSION['user_name'], $db);include("footer.inc");?>[/code]The session_start() command is in the header file, and the session variables are set on a different page. There are no errors on that page. The database variable $db is also defined in the header file, and the connection is closed in the footer file.When I log in and visit this page, my user name is echoed. I am indeed greeted by the message "You are logged in as <user name>."But then none of the relevant details show up. After elimination of possibilities I have arrived at the conclusion that for some reason $user_name is not being translated inside the mysql_query() function.You must trust me when I say that there are no problems with either the database, or the connection to it. The other pages on the site--e.g. the login page--can connect to the database and check the login information. But for some reason, this particular page is giving me a problem.Can anyone find the error?Thanks in advance for your help. Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/ Share on other sites More sharing options...
redarrow Posted July 10, 2006 Share Posted July 10, 2006 add the database okalso all whatever.inc change to whatever.php ok$result = "SELECT * FROM user_accounts_table WHERE 'user_name'='$user_name' LIMIT 1"; or die(mysql_error());$result=mysql_query($result);$table_row = mysql_fetch_assoc($result); Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/#findComment-55532 Share on other sites More sharing options...
just-j Posted July 10, 2006 Share Posted July 10, 2006 $result = mysql_query("SELECT * FROM user_accounts_table WHERE 'user_name'='$user_name' LIMIT 1", $db) or die(mysql_error());take the single 'quote out after WHERE that is rapping user_nameif it still dosent work then remove the "or die(mysql_error())". my php script wassnt wanting to work right with the "or die" using mysql_query function.hope i helped.. im a total knewb btw.. so if im way off then dont bash me to hard. Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/#findComment-55536 Share on other sites More sharing options...
Reisswolf Posted July 10, 2006 Author Share Posted July 10, 2006 [quote author=redarrow link=topic=100050.msg394404#msg394404 date=1152539303]$result = "SELECT * FROM user_accounts_table WHERE 'user_name'='$user_name' LIMIT 1"; or die(mysql_error());$result=mysql_query($result);$table_row = mysql_fetch_assoc($result)[/quote]Well, I still have the same problem.I have done the following:[code]$query_string = "SELECT * FROM accounts_table WHERE 'user_id'='" . $user_id . "' LIMIT 1";$result = mysql_query($query_string);$table_row = mysql_fetch_array($result);[/code]but my output is the same as before. Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/#findComment-55587 Share on other sites More sharing options...
designationlocutus Posted July 10, 2006 Share Posted July 10, 2006 I think it might be your quotes around 'user_id' after WHERE. It might be treating it as a string literal rather than a table field. Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/#findComment-55590 Share on other sites More sharing options...
Reisswolf Posted July 10, 2006 Author Share Posted July 10, 2006 Ah! Awesome. Thanks everyone for your help.*****By the way, I have only just signed up for this forum. I don't think there is another forum out there--for any programming language--at which help is rendered so quickly! Quote Link to comment https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/#findComment-55652 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.