Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

MySql problem

Posted on 2001-08-30
12
Medium Priority
?
244 Views
Last Modified: 2012-06-22
We have a php script (running on Red Hat Linux) that finds the username with nmblookup -A, checks the username against a database and returns some values. It worked fine on the WinNT 4 station.

However, when we moved it to Linux, we get the error:

Warning: Supplied argument is not a valid MySQL result resource in Authentication.php on line 99

$IP = $REMOTE_ADDR;
$RemoteUsersLogin = GetLoginName($IP);
$RetVal = False;
if ($RemoteUsersLogin) {
     $sql = "Select * From Users where DomainLogin='$RemoteUsersLogin'";
     $Result = mysql_query($sql,$MySqlConnection);
     if ($MyRow = mysql_fetch_array($Result)) {
                 WORK!
        }

The error happens around

$Result = mysql_query($sql,$MySqlConnection);

I tried manually typing in the sql command in the Linux shell, and it worked, it actually returned values, however when we do it this way nothing good happens.

Eric
0
Comment
Question by:theravada_maha
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +3
12 Comments
 
LVL 1

Expert Comment

by:calumscott
ID: 6441922
Try rewriting your $sql = statment thus...


$sql = "Select * From Users where DomainLogin='".$RemoteUsersLogin."'";
   
and see what happens...
0
 
LVL 1

Expert Comment

by:calumscott
ID: 6441926
That isn't very easy to read...

$sql = [double quote]Select * From Users where DomainLogin=[single quote][doublequote].$RemoteUsersLogin.[double quote][single quote][double quote];
   
0
 
LVL 4

Expert Comment

by:heddesheimer
ID: 6441987
Could it be that you won't get a valid Userlogin from GetLoginName()?
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:theravada_maha
ID: 6442052
RemoteUserLogin is IN FACT the correct username. I echoed it and it came up correctly, no spaces or extra characters or anything like that either. When I echoed the sql statement, it was correct and said "Select * from Users where DomainLogin = 'JHENDRIX'"

We suspect that it's a problem with permissions too. Any comments?

Ther.
0
 
LVL 3

Accepted Solution

by:
DarinB earned 400 total points
ID: 6442054
Hi,

You mentioned moving from NT to Linux. Is athe MySQL server on the same box as before or did you move that to.

On Linux/Unix, MySQL's table & field names are case sensitive, On NT/Windows it is not as long as you stay consistent.

Try using mysql_error() right after your query. Like this:
*****************************************
 $IP = $REMOTE_ADDR;
$RemoteUsersLogin = GetLoginName($IP);
$RetVal = False;
if ($RemoteUsersLogin) {
    $sql = "Select * From Users where DomainLogin='$RemoteUsersLogin'";
    $Result = mysql_query($sql,$MySqlConnection);
    echo mysql_error();  // <--- ADD THIS TO YOUR CODE
    if ($MyRow = mysql_fetch_array($Result)) {
                WORK!
       }
*******************************************

This will tell you exactly why MySQL failed.

darin
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6443471
how if you check the $IP. Did it value not 127.0.0.1 ? Make sure the $IP value like you need.
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6443481
I modify DarinDB script below:

*****************************************
$IP = $REMOTE_ADDR;
$RemoteUsersLogin = GetLoginName($IP);
if ($RemoteUsersLogin) {
   $sql = "Select * From Users where DomainLogin='$RemoteUsersLogin'";
   $Result = mysql_query($sql,$MySqlConnection);
   if(empty($Result)){echo mysql_error();}  // <--- ADD THIS TO YOUR CODE
   else
   {
      if ($MyRow = mysql_fetch_array($Result)) {WORK!}
   }
*******************************************
0
 
LVL 1

Expert Comment

by:fajr_n
ID: 6443496
Sorry DarinB ... my miss type your name above :)

Or display the $sql if error:

*****************************************
$IP = $REMOTE_ADDR;
$RemoteUsersLogin = GetLoginName($IP);
if ($RemoteUsersLogin) {
  $sql = "Select * From Users where DomainLogin='$RemoteUsersLogin'";
  $Result = mysql_query($sql,$MySqlConnection);
  if(empty($Result)){echo mysql_error()."<br>".$sql;}  // <--- ADD THIS TO YOUR CODE
  else
  {
     if ($MyRow = mysql_fetch_array($Result)) {WORK!}
  }
*******************************************
0
 
LVL 4

Expert Comment

by:heddesheimer
ID: 6443661
If you really got the correct username, the only solution is that it was not found in the database. Browse your database table and check if the username is in the database. For some reason something must have changed. If you need a quick code to browse your table try this:

==============================
  $sql = "select * from users";
  $result = mysql_query($sql, $MySqlConnection);
  show($result);

  function show($result)
  {
    if (!$result)
    {
        return;
    }

    if (0 == mysql_num_rows($result))
    {
        echo "nothing to show<br>\n";
        return;
    }

    $numfld = mysql_num_fields($result);
    echo "<table bgcolor=\"#CCFFFF\" border=\"1\">";
    for ($k = 0; $k < $numfld; $k++)
    {
        echo "<td>" . mysql_field_name($result, $k) . "</td>";
    }
    echo "</tr>\n";
    while ($items = mysql_fetch_row($result))
    {
      echo "<tr>";
      for ($k = 0; $k < $numfld; $k++)
      {
        echo "<td>" . $items[$k] . "&nbsp;</td>\n";
      }
      echo "</tr>\n";
    }
    echo "</table>\n";
  }
==============================

Another point could be your variable $MySqlConnection. Check if this is a valid database connection. Maybe your mysql_connect() failed in the first place for some reason and therefor you wouldn't get any results from the query. You should consider this, if you won't get a result from my code above.

Marian

0
 
LVL 3

Expert Comment

by:DarinB
ID: 6445965
Hi fajr n,

No problem on the mistype.

BTW, it is not necessary to test for an empty result since mysql_error() will be empty itself if no error occured, thus will not echo anything to the screen.


Heddesheimer,

It would not be a connection problem since PHP is actually sending the query to dB. If it was a connection problem, theravada would be getting back an invalid Link_Resource not an invalid Result Resource. Now, your suggestion may be valid if theravada IS getting an invalid Link Resource error instead.

darin
0
 

Expert Comment

by:hutieu
ID: 6459916
Linux is case-sensitive. So you should carefully check the Uppercase and lowercase of Tablenames, Fields and data field.
0
 

Author Comment

by:theravada_maha
ID: 6461106
Adding the line:

echo mysql_error();

That showed me that the table name was users not Users, on NT I guess it didn't matter. Thanks!!

Ther.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question