Page 1 of 1

supplied argument is not a valid MySQL result

Posted: Tue Sep 27, 2005 10:10 am
by cnl83
Im getting errors on a submit form that renders results, and enters results in the db. Here is the error I get on the page. Any help I get is greatly appreciated.

Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home3/cnl83/actionfx-www/classes/access_user/ext_user_profile.php on line 91

Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home3/cnl83/actionfx-www/classes/access_user/ext_user_profile.php on line 101


Here is the code for ext_user_profile.php

lines 82-116

Code: Select all

// install the "countries_table.sql" first
	function create_country_menu($label) {
		$sql_countries = sprintf("SELECT iso, name FROM %s ORDER BY id", COUNTRY_TABLE);
		$res_countries = mysql_query($sql_countries);
		$menu = "<label for=\"country\">".$label."</label>\n";
		$menu .= "<select name=\"country\">\n";
        $menu .= "  <option value=\"\"";
		$menu .= (!isset($_REQUEST['country'])) ? " selected" : "";
		$menu .= ">...\n";
    	while ($obj = mysql_fetch_object($res_countries)) {
			$menu .= "  <option value=\"".$obj->iso."\"";
			if (isset($this->country) && !isset($_REQUEST['country'])) {
				$menu .= ($obj->iso == $this->country) ? " selected" : "";
			} else {
				$menu .= (isset($_REQUEST['country']) && $obj->iso == $_REQUEST['country']) ? " selected" : "";
			}
			$menu .= ">".$obj->name."\n";
    	}
		$menu .= "</select><br>\n";
		mysql_free_result($res_countries);
		return $menu;
	}
	function create_form_field($formelement, $label, $length = 25, $required = false) {
		$form_field = "<label for=\"".$formelement."\">".$label."</label>\n";
		$form_field .= "  <input name=\"".$formelement."\" type=\"text\" size=\"".$length."\" value=\"";
		if (isset($_REQUEST[$formelement])) {
			$form_field .= $_REQUEST[$formelement];
		} elseif (isset($this->$formelement) && !isset($_REQUEST[$formelement])) {
			$form_field .= $this->$formelement;
		} else {
			$form_field .= "";
		}
		$form_field .= ($required) ? "\">*<br>\n" : "\"><br>\n";
		return $form_field;		
	}
and this is particularly line 91

Code: Select all

while ($obj = mysql_fetch_object($res_countries)) {

Posted: Tue Sep 27, 2005 10:17 am
by $var
Why do you have a comma after iso?
Try removing that and using AND if you are trying to join.

If you are getting invalid sql statements, sometimes it has to do with a lack of information that stems from variables that aren't passing.

Posted: Tue Sep 27, 2005 10:20 am
by shiznatix
the comma is cool where it is. that is not the problem.

change

$res_countries = mysql_query($sql_countries);

to

$res_countries = mysql_query($sql_countries) or die(mysql_error());

that will give you a mysql error becuase i am perdy sure you can't use %s as a table name, you should have to put in a real and complete table name. try doing that

Posted: Tue Sep 27, 2005 10:23 am
by cnl83
I replaced that string..and I got this..

Unknown column 'iso' in 'field list'

Posted: Tue Sep 27, 2005 10:34 am
by shiznatix
then the collum iso does not exist in that table. make sure you spelled everything correctly

Posted: Tue Sep 27, 2005 10:38 am
by cnl83
CREATE TABLE `countries` (
`id` int(11) NOT NULL auto_increment,
`iso` char(2) NOT NULL default '',
`name` varchar(100) NOT NULL default '',
PRIMARY KEY (`id`)
) TYPE=MyISAM;


I deleted the entire table, and re-created it. Now it works..
thanks for the help.

Posted: Tue Sep 27, 2005 10:48 am
by shiznatix
glad its working now