Jump to content

Recommended Posts

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.
Link to comment
https://forums.phpfreaks.com/topic/14173-strange-problem-with-mysql_query/
Share on other sites

add the database ok

also 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);
 $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_name

if 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 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.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.