Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource

Discussion in 'MySQL' started by 010081, Feb 1, 2007.

  1. #1
    i encounter following problem
    Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result in myserver/members.inc on line 16

    i've enclosed code
    
    <?php
    	//session_start();
    	/*if(!strstr($_SERVER['HTTP_USER_AGENT'],"MSIE"))
    	{
    		echo '<div class="video">Please use Internet Explorer to view this site!</div>';
    		exit();	
    	}*/
    	list($username, $password) = explode("|",$_COOKIE["mediaManager2"]);
    	include("db.php");
    	$logged_in = false;
    	$query = "SELECT * FROM users where username = '".$username."' and password = '".$password."'";
    	$rs = mysql_query($query);
    
    	global $link_list;
    
    	if($data = mysql_fetch_array($rs))
    	{
    		$userId = $data['id'];
    		$user_name = $data['name'];
    		$link_list = $data['link'];
    		$isAdmin = $data['admin'];
    		list($selectedLink, $others) = explode(",",$link_list);
    		$logged_in = true;
    	}
    	else
    	{
    		echo 'Sorry you are not authorized to view this page! If you loggedin properly and still this message, please make sure your browser has cookies enabled! <a href="index.html">Continue</a>';
    		exit();
    	}
    
    	function getUserID()
    	{
    		global $userId;
    		return $userId;
    	}
    
    	function getName()
    	{
    		global $user_name;
    		return $user_name;
    	}
    
    	function isUserAdmin()
    	{
    		global $isAdmin;
    		if($isAdmin == 1)
    		{
    			return true;
    		}
    		return false;
    	}
    ?>
    </code> 
    PHP:
    plz help
     
    010081, Feb 1, 2007 IP
  2. amnezia

    amnezia Peon

    Messages:
    990
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    it means you havent connected to the database correctly
     
    amnezia, Feb 1, 2007 IP
  3. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #3
    from your code, i'm assuming the connection to the database is made from the db.php inlude file?

    anyway, the problem is probably because the sql statement is either wrong (syntax) or it did not return any results.

    do this:
    1. add a print command below

    $query = "SELECT * FROM users where username = '".$username."' and password = '".$password."'";
    Code (markup):
    look at the output - is the syntax ok?

    if ok, run it against the database table directly - any results?

    you should add additional checking into your code - add an if statement to check if the query returns any results:

    after:
    $rs = mysql_query($query);
    Code (markup):
    add the following:
    if(mysql_num_rows() > 0) {
       ...processing if got results
    }
    else {
       ...processing if no results
    }
    Code (markup):
     
    daboss, Feb 1, 2007 IP
  4. 010081

    010081 Banned

    Messages:
    4,657
    Likes Received:
    222
    Best Answers:
    0
    Trophy Points:
    0
    #4
    also when i import mql file from phpmyadmin i get following error
    
    #1064 - 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 'DEFAULT CHARSET=latin1' at line 11 
    Code (markup):
    the mysql data i tried to import

    
    
    -- 
    -- Table structure for table `packages`
    -- 
    
    CREATE TABLE `packages` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(255) NOT NULL default '',
      `price` varchar(255) NOT NULL default '',
      `server` varchar(255) NOT NULL default '',
      `comments` varchar(255) NOT NULL default '',
      `active` varchar(255) NOT NULL default '',
      `bitrate` varchar(255) NOT NULL default '331',
      `showOrder` varchar(255) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    -- 
    -- Dumping data for table `packages`
    -- 
    
    INSERT INTO `packages` (`id`, `name`, `price`, `server`, `comments`, `active`, `bitrate`, `showOrder`) VALUES (1, 'Demo Package', 'FREE', '1', 'Demo Stream !', '1', '331', '1');
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `servers`
    -- 
    
    CREATE TABLE `servers` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(255) NOT NULL default '',
      `ip` varchar(255) NOT NULL default '',
      `pubPoint` varchar(255) NOT NULL default '',
      `cap` varchar(255) NOT NULL default '',
      `full` varchar(255) NOT NULL default '',
      `active` varchar(255) NOT NULL default '',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    -- 
    -- Dumping data for table `servers`
    -- 
    
    INSERT INTO `servers` (`id`, `name`, `ip`, `pubPoint`, `cap`, `full`, `active`) VALUES (1, 'Demo Server', '255.255.255.255', 'demo', '100', '0', '1');
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `syssettings`
    -- 
    
    CREATE TABLE `syssettings` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(255) NOT NULL default '',
      `value` varchar(255) NOT NULL default '',
      `locked` varchar(20) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    -- 
    -- Dumping data for table `syssettings`
    -- 
    
    INSERT INTO `syssettings` (`id`, `name`, `value`, `locked`) VALUES (1, 'Paypal ID', 'payment@imysite.com', '0');
    INSERT INTO `syssettings` (`id`, `name`, `value`, `locked`) VALUES (2, 'Encryption Key', '26', '1');
    INSERT INTO `syssettings` (`id`, `name`, `value`, `locked`) VALUES (3, 'Admin Email', 'email@gmail.com', '0');
    INSERT INTO `syssettings` (`id`, `name`, `value`, `locked`) VALUES (4, 'Base Url', 'http://www.mysiteb.com/', '0');
    
    -- --------------------------------------------------------
    
    -- 
    -- Table structure for table `users`
    -- 
    
    CREATE TABLE `users` (
      `id` int(11) NOT NULL auto_increment,
      `name` varchar(255) NOT NULL default '',
      `email` varchar(255) default NULL,
      `username` varchar(255) default NULL,
      `password` varchar(255) default NULL,
      `ip` varchar(255) default NULL,
      `link` varchar(255) default '14',
      `lastlogin` varchar(255) default NULL,
      `active` varchar(255) default NULL,
      `banned` varchar(255) default '0',
      `paid` binary(1) NOT NULL default '0',
      `proxy` varchar(255) NOT NULL default '0',
      `session` text NOT NULL,
      `owner` varchar(255) NOT NULL default 'OBAID',
      `admin` varchar(255) NOT NULL default '0',
      PRIMARY KEY  (`id`)
    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    
    -- 
    -- Dumping data for table `users`
    -- 
    
    INSERT INTO `users` (`id`, `name`, `email`, `username`, `password`, `ip`, `link`, `lastlogin`, `active`, `banned`, `paid`, `proxy`, `session`, `owner`, `admin`) VALUES (1, 'BMDESI Admin', 'admin@bmddsesi.com', 'admin@bmsdddesi.com', 'changeme', '', '1,', '2006/03/5 17:45:27', '1', '0', 0x31, '0', '', '1', '1');
    
    PHP:
     
    010081, Feb 1, 2007 IP
  5. daboss

    daboss Guest

    Messages:
    2,249
    Likes Received:
    151
    Best Answers:
    0
    Trophy Points:
    0
    #5
    look for:

    ) ENGINE=MyISAM DEFAULT CHARSET=latin1;
    Code (markup):
    and replace that with:

    ) ENGINE=MyISAM;
    Code (markup):
    should work... ;)
     
    daboss, Feb 1, 2007 IP
  6. 010081

    010081 Banned

    Messages:
    4,657
    Likes Received:
    222
    Best Answers:
    0
    Trophy Points:
    0
    #6
    thanx daboss it worked perfectly fine

    but i also have following error

    i'm getting following error
    Fatal error: Call to undefined function: curl_init() in /home/sitename/common.php on line 230


    and here is that common.php from link 230 - 239
    
    
    		$ch = curl_init();
    		curl_setopt($ch, CURLOPT_URL, $url);
    		curl_setopt ($ch, CURLOPT_POST, 1);
    		curl_setopt ($ch, CURLOPT_POSTFIELDS, "pubId=".$pubPoint."&username=".$username);
    		#curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
    		curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
    		//$store = curl_exec ($ch);
    		$content = curl_exec ($ch); # This returns HTML
    		return $content;
    		curl_close ($ch);
    
    PHP:
    plz point me the wrong

    thanx in advance
     
    010081, Feb 1, 2007 IP
  7. aplus

    aplus Well-Known Member

    Messages:
    83
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    115
    #7
    do a
    
    <?php phpinfo(); ?>
    
    PHP:
    and look for the curl section. If there is none, then you will have to recompile php with curl support.
     
    aplus, Feb 1, 2007 IP
  8. moin1407

    moin1407 Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Hi

    I know this is a very old thread. I have replied that for the all future visitors with a view to helping them:

    see below:

    $result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");

    Cart is table name here. I know that when table name is too short and without underscore thn mql shows the error. because mysql can not detect short name. when table name is too short and without underscore thn you must have to add ` both side of the table name in query. Or if u dont want to add ` thn select a name with a underscore or select a long name.

    See example and try below one and both will work :

    $result = mysql_query("select count(*) from `cart` where cookieId = '" . GetCartId() . "' and itemId = $itemId");

    or,

    $result = mysql_query("select count(*) from cart_1 where cookieId = '" . GetCartId() . "' and itemId = $itemId");
     
    moin1407, Nov 18, 2010 IP