Jump to content

[SOLVED] error only when hosted on a website


gsquare567

Recommended Posts

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in abc.php on line 57

 

and my code is:

$find_user = $_GET['username'];

$result = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");

if($row = mysql_fetch_array($result))

Link to comment
Share on other sites

You should check to see whether you're getting an MySQL error on the query. That should tell you more. Plus, you really should sanitize the input to guard against MySQL insertion attacks by using the function mysql_real_escape_string()

<?php
$find_user = mysql_real_escape_string(stripslashes($_GET['username']));
$query = "SELECT * FROM AuthDB WHERE Username = '$find_user'";
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre>" . mysql_error());
if($row = mysql_fetch_array($result))
?>

 

Ken

Link to comment
Share on other sites

well, when i add in an echo

$find_user = $_GET['username'];
echo "SELECT * FROM AuthDB WHERE Username = '$username'";
$result = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");

if($row = mysql_fetch_array($result))

and the url ends with /abc.php?username=test&password=abcdef, it says:

SELECT * FROM AuthDB WHERE Username = 'test'
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

 

so it has nothing to do with the result variable

Link to comment
Share on other sites

ok, i understood that it wasnt in the db, then apparently my db was deleted, so i made a new one and now i get this:

SELECT * FROM AuthDB WHERE Username = 'test'Problem with the query

Resource id #2

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1

Link to comment
Share on other sites

$find_user = $_GET['username'];
echo "SELECT * FROM AuthDB WHERE Username = '$username'";

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");
$result = mysql_query($query) or die("Problem with the query <pre>$query</pre>" . mysql_error());

if($row = mysql_fetch_array($result))

Link to comment
Share on other sites

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");

$result = mysql_query($query) or die("Problem with the query <pre>$query</pre>" . mysql_error());

 

Man, do you understand what your code is attempting?

 

Seriously, you need to learn to debug. Always check your queries actually succeed before trying to use any results from them.

 

<?php

  $find_user = mysql_real_escape_string(stripslashes($_GET['username']));
  $query = "SELECT * FROM AuthDB WHERE Username = '$find_user'";
  if ($result = mysql_query($query)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        // display the data.
      }
    } else {
      echo "No results found";
    }
  } else {
    echo "Problem with the query <pre>$query</pre>" . mysql_error();
  }

?>

Link to comment
Share on other sites

same errors basically:

Problem with the query

Resource id #2

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Resource id #2' at line 1
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Link to comment
Share on other sites

That simply is not possible. Nothing in Ken's code or Thorpe's code would echo "resource id" anything.  Sounds like you still haven't made your code the same as the perfectly good code that's been offered to you.

Link to comment
Share on other sites

maybe its the code after it:

if($row = mysql_fetch_array($result))
{
// password checking
$find_pass = $_GET['password'];
if($row['Password'] == $find_pass)
{
	// ip checking
	$find_ip = $_SERVER['REMOTE_ADDR'];
	$ip = $row['IP'];
	if($row['IP'] == $find_ip || strlen($ip) == 0)
	{
		if(strlen($ip) == 0) // set ip if not already set
		{
			mysql_query("UPDATE AuthDB SET IP = '$find_ip' WHERE Username = '$find_user'");
		}

		$find_time = date("l, F jS, Y") . " at " . date("g:i:s A");
		mysql_query("UPDATE AuthDB SET Last Login = '$find_time' WHERE Username = '$find_user'");			

		$valid = true;
	}
}
}

Link to comment
Share on other sites

i dont get it, what's resource #2? is it like an explosive bomb or somethin? i'll post all my code:

 

<?php
$mysql_host = '**********';
$mysql_user = '***********';
$mysql_pass = '*******';
$mysql_db = '**********';

// mysql connecting
$dbc = mysql_connect($mysql_host, $mysql_user, $mysql_pass)
or DIE('Could not connect to the MySQL server: ' . mysql_error());

mysql_select_db($mysql_db, $dbc) or DIE('Could not select the database: ' . mysql_error());

$valid = false;

if ($_SERVER["HTTP_X_FORWARDED_FOR"] != "")
{
$IP = $_SERVER["HTTP_X_FORWARDED_FOR"];
$proxy = $_SERVER["REMOTE_ADDR"];
$host = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
else
{
$IP = $_SERVER["REMOTE_ADDR"];
$host = $IP;
}
echo "HOST: " . $host . "<br>";
echo "PROXY: " . $proxy . "<br>";
echo "IP: " . $ip . "<br>";

// username checking
$find_user = $_GET['username'];
echo "SELECT * FROM AuthDB WHERE Username = '$username'";

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");
//$result = mysql_query($query) or die("Problem with the query <pre>$query</pre>" . mysql_error());

if ($result = mysql_query($query)) {
    if (mysql_num_rows($result)) {
      while ($row = mysql_fetch_assoc($result)) {
        // display the data.
        echo $row['Username'];
      }
    } else {
      echo "No results found";
    }
  } else {
    echo "Problem with the query <pre>$query</pre>" . mysql_error();
  }

if($row = mysql_fetch_array($result))
{
// password checking
$find_pass = $_GET['password'];
if($row['Password'] == $find_pass)
{
	// ip checking
	$find_ip = $_SERVER['REMOTE_ADDR'];
	$ip = $row['IP'];
	if($row['IP'] == $find_ip || strlen($ip) == 0)
	{
		if(strlen($ip) == 0) // set ip if not already set
		{
			mysql_query("UPDATE AuthDB SET IP = '$find_ip' WHERE Username = '$find_user'");
		}

		$find_time = date("l, F jS, Y") . " at " . date("g:i:s A");
		mysql_query("UPDATE AuthDB SET Last Login = '$find_time' WHERE Username = '$find_user'");			

		$valid = true;
	}
}
}

if($valid)
{
echo "ACCEPTED";
}
else
{
echo "DENIED";
}
?>

Link to comment
Share on other sites

Look. Here you assign the resource returned by mysql_query to the variable $query.

 

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");

 

Then, here you try an execute a query using that same resource stored in $query.

 

Do you even know what mysql_query returns?

 

if ($result = mysql_query($query)) {

 

You need to do some tutorials on basic database querying. Were here to help with code, not teach you step by step.

Link to comment
Share on other sites

Replace these three lines:

<?php
$find_user = $_GET['username'];
echo "SELECT * FROM AuthDB WHERE Username = '$username'";

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");
?>

with

<?php
$find_user = mysql_real_escape_string(stripslashes($_GET['username']));
$query = "SELECT * FROM AuthDB WHERE Username = '$username'";

$result = mysql_query($query) or die("Problem with the query <pre>$query</pre><br>" . mysql_error());
?>

 

Ken

 

Link to comment
Share on other sites

Look. Here you assign the resource returned by mysql_query to the variable $query.

 

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");

 

Then, here you try an execute a query using that same resource stored in $query.

 

Do you even know what mysql_query returns?

 

if ($result = mysql_query($query)) {

 

You need to do some tutorials on basic database querying. Were here to help with code, not teach you step by step.

 

false if didnt work or a value if true

Link to comment
Share on other sites

Its a resource actually, not a value. So then... can you explain why you have the code you have?

 

$query = mysql_query("SELECT * FROM AuthDB WHERE Username = '$find_user'");
if ($result = mysql_query($query)) {

 

How does that make sense?

Link to comment
Share on other sites

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.