Jump to content


Photo

Strange Problem with mysql_query()


  • Please log in to reply
5 replies to this topic

#1 Reisswolf

Reisswolf
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 July 2006 - 01:43 PM

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:

<?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");

?>

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.

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 10 July 2006 - 01:48 PM

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);

Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 just-j

just-j
  • Members
  • PipPipPip
  • Advanced Member
  • 52 posts

Posted 10 July 2006 - 01:53 PM

 $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.

#4 Reisswolf

Reisswolf
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 July 2006 - 03:07 PM

$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)

Well, I still have the same problem.

I have done the following:

$query_string = "SELECT * FROM accounts_table WHERE 'user_id'='" . $user_id . "' LIMIT 1";
$result = mysql_query($query_string);
$table_row = mysql_fetch_array($result);

but my output is the same as before.

#5 designationlocutus

designationlocutus
  • Members
  • PipPipPip
  • Advanced Member
  • 62 posts

Posted 10 July 2006 - 03:11 PM

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.

#6 Reisswolf

Reisswolf
  • Members
  • PipPip
  • Member
  • 13 posts

Posted 10 July 2006 - 05:10 PM

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!




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users