when im test in my local machine i dont have any error but when im trying to test in web i have this error, the same DB, the same tables, the same data in both structures any idea????

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site244/fst/var/www/html/categoria.php on line 107

<?php
    require('conexion2.php');
    $SQLEmpresa= "SELECT empresa.cve_Empresa, Nombre, Direccion, pagina, telefono 
	             FROM empresa, empresa_Categoria  
		WHERE ".$_GET['cve_Categoria']." = empresa_Categoria.cve_Categoria 
		 AND empresa_Categoria.cve_Empresa = empresa.cve_Empresa";
    $rsEmpresa = mysql_query($SQLEmpresa,$conexion);
	$reg = array();
-->line 107	while ($reg = mysql_fetch_array($rsEmpresa))
	   {		
			$nombre =  $reg["Nombre"]; 
			$direccion =  $reg["Direccion"]; 
			$telefono =  $reg["telefono"]; 						
			$pagina = $reg["pagina"];
			$cve_Empresa = $reg["cve_Empresa"];	   					
?>

Your local machine does not show because you have turned off the error reporting. Anyway try the below code. Do let me know whether it works.

<?php
    require('conexion2.php');
    $SQLEmpresa= "SELECT empresa.cve_Empresa, Nombre, Direccion, pagina, telefono 
	             FROM empresa, empresa_Categoria  
		WHERE ".$_GET['cve_Categoria']." = empresa_Categoria.cve_Categoria 
		 AND empresa_Categoria.cve_Empresa = empresa.cve_Empresa";
    $rsEmpresa = mysql_query($SQLEmpresa,$conexion);
	while ($reg = mysql_fetch_array($rsEmpresa))//line 107
	   {		
			$nombre =  $reg["Nombre"]; 
			$direccion =  $reg["Direccion"]; 
			$telefono =  $reg["telefono"]; 						
			$pagina = $reg["pagina"];
			$cve_Empresa = $reg["cve_Empresa"]
} // You forget to close while loop					
?>

tnx for your time the error was i had the table empresa_Categoria whit upper case
and the name of the table is empresa_categoria with lower case
tnx a lot for your time

Yep, character case is extremely important both in MySQL and in PHP - I suggest most of the time to keep things in lowercase ;)

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource...this is the same bug i am fed of it...please do some help...I am trying to retrieve record from the database from sa_settings table but to retrieve the information related to product, i have to go to the table cards to look up for ProductID in it....i got one record from the database but why the hell that While loop search for another record when I dont have any other record in the table...this is sucking my mind and i am trying to get over it for the last two days...hope u guyz could help me out of it..

<DIV id="<?PHP echo ($_GET['ID']); ?>">
 <table width="100%" border="0" cellspacing="0" cellpadding="0">
 <tr align="center" valign="top">
 <td height="16" colspan="3" bgcolor="#FFFFFF"><strong><font color="#000066" size="1" face="Tahoma" style="bold"><?PHP echo ($_GET['ID']); ?></font></strong></td>
                                              </tr>
                                              <tr align="center" valign="top"> 
                                                <td height="16" colspan="3" bgcolor="#FFFFFF">&nbsp;</td>
                                              </tr>
                                              <?php
                $User_name=$_GET['ID']; 
              $sql="select * from sa_settings where username='$User_name'";
              $result = mysql_query ($sql) or die("Query error: ". mysql_error());
              $counter=0;
              mysql_num_rows($result);
              if(mysql_num_rows($result)>0)
               {
               while($rs=mysql_fetch_array($result))
                {
                $counter=$counter+1;
                $PID=$rs['ProductID'];
                $COMM=$rs['Commision'];
                $sql="select * from cards WHERE CardID=$PID";
                $result=mysql_query($sql);
             ?>
                                              <tr valign="top"> 
                                                <td height="16" bgcolor="#FFFFFF"><?php echo $result['CardName']; ?>&nbsp;</td>
                                                <td width="134" height="16" bgcolor="#FFFFFF"><?php echo $result['Price']; ?></td>
                                                <td width="151" bgcolor="#FFFFFF"><input name="Commision<?php echo $counter; ?>" type="text" id="Commision<?php echo $counter; ?>" value="<?php echo $COMM; ?>" size="7"></td>
                                              </tr>
                                              <?php
               }

                }           
             ?>

the schema for the two tables are as follows;

cards table
-------------
CardID
CardName
Price
Status






sa_settings table
-------------------
usID
username
ProductID --> CardID
Commision

I want to retrieve CardName from cards table, I get one such result but there is no second result and While loop is again entering in to its body to look up for the record...why??????

I have tested the queries on mySQL engine and they are giving me only one result per record. What is wrong with the code...

This is the snapshot of my output that I am getting with the following error string...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /data/12/1/9/102/1172754/user/1246647/htdocs/MasterAgent/viewsuperagent.php on line 240

and I have this on line 240

while($rs=mysql_fetch_array($result))


Owais

Owais


Why this second text box is comming....

check your query. If you get the not supplied valid arguement, 99.9% of the time. the problem is in your query. Echo out your query and check it to make sure that is working properly. This can be done any place that you can free-form a MySQL query in your database. Check to make sure it is workign properly.

Having the same issue, using a previous page as a template which does connect, so I would think there are no issues there. When i cut and paste the sql statement into phpmyadmin it works fine. It is a rather lengthy sql statement and complicated using temorary tables.

$statistics = mysql_query("CREATE TEMPORARY TABLE set1 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set1
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '1'
GROUP BY users.id;


CREATE TEMPORARY TABLE set2 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set2
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '2'
GROUP BY users.id;

CREATE TEMPORARY TABLE set3 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set3
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '3'
GROUP BY users.id;

CREATE TEMPORARY TABLE set4 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set4
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '4'
GROUP BY users.id;

CREATE TEMPORARY TABLE set5 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set5
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '5'
GROUP BY users.id;

CREATE TEMPORARY TABLE set6 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set6
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '6'
GROUP BY users.id;

CREATE TEMPORARY TABLE set7 (
id VARCHAR(5) NOT NULL
, score VARCHAR(5) NOT NULL DEFAULT 0
, totalscore VARCHAR(5) NOT NULL NOT NULL DEFAULT 0
, time timestamp NOT NULL
, setid VARCHAR(5) NOT NULL
) ;

INSERT INTO set7
(id, score, totalscore, time, setid)
SELECT
users.id, statistics.score, statistics.totalscore, MAX(statistics.time), sets.id
FROM users, statistics, sets
WHERE users.id = statistics.userid
AND statistics.setid = sets.id
AND sets.id = '7'
GROUP BY users.id;

SELECT D.last, D.first,
D.dept, D.duties, D.doh,
set1.setid, set1.score, set1.totalscore, set1.time,
set2.setid, set2.score, set2.totalscore, set2.time,
set3.setid, set3.score, set3.totalscore, set3.time,
set4.setid, set4.score, set4.totalscore, set4.time,
set5.setid, set5.score, set5.totalscore, set5.time,
set6.setid, set6.score, set6.totalscore, set6.time,
set7.setid, set7.score, set7.totalscore, set7.time
FROM directory2 AS D
LEFT JOIN users AS U ON D.last = U.last_name
LEFT JOIN set1 USING (id)
LEFT JOIN set2 USING (id)
LEFT JOIN set3 USING (id)
LEFT JOIN set4 USING (id)
LEFT JOIN set5 USING (id)
LEFT JOIN set6 USING (id)
LEFT JOIN set7 USING (id)
WHERE D.dept = '01 - Atlanta'
GROUP BY last
".$limiting);

while($astatistics = mysql_fetch_array($statistics)){
AND IT DIES RIGHT HERE. HAVE TRIED THIS A FEW DIFFERENT WAYS AND IT WILL NOT EXECUTE THE QUERY - ANY IDEAS?
Actually this is a a series of sql statments separated by semicolons, it works in phpmyadmin , should they be separate sql statements?

I am also getting this error ? Any help would greatly be appreciated.

Thanks MrTerry

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/bluestar/public_html/forum/admin/admin_ideas.php on line 94

<?php
/***************************************************************************
 *                              admin_ideas.php
 *                            -------------------
 *   begin                : Saturday, Jul 28, 2007
 *   copyright            : (C) 2007 Funender.com
 *   email                : [email]admin@funender.com[/email]
 *
 *   $Id:lang_admin_ideas.php,v 1.0.1 2007/07/28 23:24:01 FuNEnD3R Exp $
 *
 *
 ***************************************************************************/


define('IN_PHPBB', 1);

if( !empty($setmodules) )
{
	$file = append_sid("admin_ideas.$phpEx").'&amp;mode=view';
	$module['General']['Admin_Ideas'] = $file;
	return;
}

//
// Let's set the root dir for phpBB
//
$phpbb_root_path = "./../";
require($phpbb_root_path . 'extension.inc');
require('./pagestart.' . $phpEx);
require($phpbb_root_path . 'language/lang_' . $board_config['default_lang'] . '/lang_admin_ideas.' . $phpEx);
include($phpbb_root_path . 'includes/functions_selects.'.$phpEx);


     $status = array("0" => $lang['pending'],
					 "1" => $lang['testing'],
					 "2" => "<font color=\"green\">".$lang['done']."</font>",
					 "3" => "<font color=\"red\">".$lang['denied']."</font>");

if($_GET["mode"] == "view" || $_POST["mode"] == "view") {

				$template->set_filenames(array(
					"body" => "admin/admin_ideas.tpl")
					);
		
				$template->assign_vars(array(
								 "ADD_NEW_IDEA" => $lang['Add_New_Idea'],
								 "SAVE" => $lang['Save'],
								 "TESTING" => $lang['Testing'],
								 "COMPLETE" => $lang['Complete'],
								 "DENY" => $lang['Deny'],
								 "FILTER" => $lang['Filter'],
								 "EDIT" => $lang['Edit'],
								 "DELETE" => $lang['Delete'],
								 "CURRENTLY" => $lang['Currently_Working'],
								 "ADDED" => $lang['New_Idea_Added'],
								 "WISH" => $lang['Do_Not_Wish'],
								 
								 "F_NONE" => $lang['Filter_none'],
								 "F_PENDING" => $lang['Filter_pending'],
								 "F_TESTING" => $lang['Filter_testing'],
								 "F_DONE" => $lang['Filter_done'],
								 "F_DENIED" => $lang['Filter_denied'],
								 
								 "S_DATE" => $lang['Status_Date'],
								 "S_USER" => $lang['Status_User'],
								 "S_IDEA" => $lang['Status_Idea'],
								 "S_STATUS" => $lang['Status_Status'],
								 "S_OPTIONS" => $lang['Status_Options'],
									
								 "B_WRITE" => $lang['Admin_Written'],
								 "B_SUBMIT" => $lang['Add_Submit'],
	
	                             "U_IDEA_ACTION" => append_sid("admin_ideas.$phpEx"),
                        	     "U_IDEA_ALL"  => append_sid("?mode=view"),
							     "U_IDEA_ORD1" => append_sid("?mode=view&amp;orderby=0"),
							     "U_IDEA_ORD2" => append_sid("?mode=view&amp;orderby=1"),
							     "U_IDEA_ORD3" => append_sid("?mode=view&amp;orderby=2"),
							     "U_IDEA_ORD4" => append_sid("?mode=view&amp;orderby=3"))
								 );
	

	$orderby = $_GET[orderby];
	if($orderby != '')
	{
		$res = mysql_query("SELECT * FROM phpbb_newideas WHERE idea_status='$orderby' ORDER BY idea_id DESC");
	}
	else
	{
	   $res = mysql_query("SELECT * FROM phpbb_newideas ORDER BY idea_status ASC, idea_id DESC");
	}
	
	while($row = mysql_fetch_array($res)) {
		$resb = mysql_query("SELECT username FROM phpbb_users WHERE user_id = '".$row["user_id"]."'");
		$rowb = mysql_fetch_array($resb);
		
		if($row["idea_status"] == 1) {
			$opt1 = append_sid("?mode=status&amp;idea_id=".$row["idea_id"]."&amp;status=0");
		} else {
			$opt1 = append_sid("?mode=status&amp;idea_id=".$row["idea_id"]."&amp;status=1");
		}
				  $vars = array("IDEA_TIME"   => date("m/d/Y", $row["idea_time"]),
							    "IDEA_TEXT"   => nl2br(htmlspecialchars($row["idea_text"], HTML_ENTITIES)),
							    "IDEA_STATUS" => $status[$row["idea_status"]],
							    "USER_NAME"   => htmlspecialchars($rowb["username"], HTML_ENTITIES),
	
							    "IDEA_OPT1"   =>  $opt1,
							    "IDEA_OPT2"   =>  append_sid("?mode=status&amp;idea_id=".$row["idea_id"]."&amp;status=2"),
							    "IDEA_OPT3"   =>  append_sid("?mode=status&amp;idea_id=".$row["idea_id"]."&amp;status=3"),
							    "IDEA_OPT4"   =>  append_sid("?mode=edit&amp;idea_id=".$row["idea_id"]),
							    "IDEA_OPT5"   =>  append_sid("?mode=del&amp;idea_id=".$row["idea_id"]));
				$template->assign_block_vars("idearow", $vars);
			}
			$template->pparse("body");
}

if($_POST["save_idea"]) {
	   $idea_text = $_POST["idea_text"];
	   if(strlen($idea_text) <= 0) {
			$message = $lang['Enter_Message'] . "<br /><br /><a href=\"javascript:history.go(-1)\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
			 message_die(GENERAL_MESSAGE, $message);
	   }
	
	   $sql = "INSERT INTO phpbb_newideas (idea_text, idea_time, user_id) 
	           VALUES('".$_POST["idea_text"]."', '".time()."', '".$userdata["user_id"]."')";
			   
		if( !$result = $db->sql_query($sql) )
		{
		      message_die(GENERAL_ERROR, "Couldn't insert into idea table", "", __LINE__, __FILE__, $sql);
		}
		
		   $message = $lang['Idea_Saved'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
		    message_die(GENERAL_MESSAGE, $message);
}

if($_GET["mode"] == "status") {
	   $sql = "UPDATE phpbb_newideas SET idea_status = '".$_GET["status"]."' WHERE idea_id = '".$_GET["idea_id"]."'";
		if( !$result = $db->sql_query($sql) )
		{
			 message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
		}
		
		  $message = $lang['Status_Updated'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
		   message_die(GENERAL_MESSAGE, $message);
}


if($_GET["mode"] == "del") {
	   $sql = "DELETE FROM phpbb_newideas WHERE idea_id = '".$_GET["idea_id"]."'";
		if( !$result = $db->sql_query($sql) )
		{
			 message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
		}
		
		 $message = $lang['Idea_Deleted'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
		  message_die(GENERAL_MESSAGE, $message);
}

if($_GET["mode"] == "edit") {
	   $sql = "SELECT idea_text, idea_id FROM phpbb_newideas WHERE idea_id = '".$_GET["idea_id"]."'";
		if( !$result = $db->sql_query($sql) )
		{
			 message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
		}
		
	$row = mysql_fetch_array($result);
	
	         $template->set_filenames(array(
	         "body" => "admin/admin_ideas_edit.tpl")
	         );
			 
	        $template->assign_vars(array(
			                     "EDIT_IDEA" => $lang['Edit_Idea'],
								 "SAVE" => $lang['Save'],
	                             "IDEA_TEXT" => htmlspecialchars($row["idea_text"], HTML_ENTITIES), 
	                             "IDEA_ID" => $row["idea_id"],
								 
								 "B_WRITE" => $lang['Admin_Written'],
								 "B_SUBMIT" => $lang['Add_Submit'],
								 
								 "U_IDEA_ACTION" => append_sid("admin_ideas.$phpEx"))
								 );
	        $template->pparse("body");
}

if($_POST["save_edit_idea"]) {
	   $sql = "UPDATE phpbb_newideas SET idea_text = '".$_POST["idea_text"]."' WHERE idea_id = '".$_POST["idea_id"]."'";
		if( !$result = $db->sql_query($sql) )
		{
			message_die(GENERAL_ERROR, "Couldn't update idea table", "", __LINE__, __FILE__, $sql);
		}
		
		$message = $lang['Idea_Edited'] . "<br /><br /><a href=\"".append_sid("admin_ideas.$phpEx?mode=view")."\">". sprintf($lang['Click_Here_Go_Back'] . "</a>");
		 message_die(GENERAL_MESSAGE, $message);
}


include('./page_footer_admin.'.$phpEx);

?>

Hi
I am developing a simple login system for college project.
Facing difficulty in getting this code working.

It is showing the same error:

"Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/pakistan/public_html/checklogin.php on line 11 Login unsuccessful!Either your UserID or your Password is incorrect.

Please put the right UserID or Password, otherwise register yourself Back" 

here is the code:

<?php
session_start();

    $conn = mysql_connect('localhost', 'user', 'password');

    $result = mysql_query('select * from Customer where 
    UserID = "'. $_POST[UserID].'" And Password = "'. $_POST[Password].'"');
    $row = mysql_fetch_array($result);
    if ($row[UserID]==$_POST['UserID'])
    {
    echo 'Login successful';
    echo 'Please click on';
    echo "</br><a href=\"Tshirt.php\"> T-Shirt</a>";
    }
    else
    {
    echo '<blink><font color=\”red\”>Login unsuccessful!'; 
    echo 'Either your UserID or your Password is incorrect.';
    echo '</br>Please put the right UserID or Password, otherwise register yourself';
    echo "</br><a href=\"Shopping.php\"> Back</a>";
    }
?>

can anybody tell me where the problem is?
thanks

$user_id=$_POST['UserID'];
$password=$_POST['Password'];
$query="select * from Customer where
UserID = '$user_id' and Password = '$password'";
echo $query;
$result=mysql_query($query) or die(mysql_error());

Check what $query prints. Execute the same in phpmyadmin.

oh, and please, next time you post your code, put it in [code] tags.

y need some help pls
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\xxxxxxxxx\index.php on line 7
No Template Selected

require("dbconfig.php");
$con =mysql_connect ($db_host,$db_user,$db_pass) or die("Error connecting");
mysql_select_db($db_name,$con);
$tem="select dir from template where active='1'";
$temr=mysql_query($tem,$con);
$temn=mysql_num_rows($temr);   line 7 
if($temn==0)

y need some help pls
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in c:\xxxxxxxxx\index.php on line 7
No Template Selected


require("dbconfig.php");
$con =mysql_connect ($db_host,$db_user,$db_pass) or die("Error connecting");
mysql_select_db($db_name,$con);
$tem="select dir from template where active='1'";
$temr=mysql_query($tem,$con);
$temn=mysql_num_rows($temr); line 7
if($temn==0)

Excuse me. Did you not see the GIANT GLARING STICKIED POST that said "FAQ: Supplied argument not valid resource"? How about you go back and take a look at that.

$rsEmpresa = mysql_query($SQLEmpresa,$conexion) or die(mysql_error());
//add the text shown in BOLD, this will atleast display what error you are having

when im test in my local machine i dont have any error but when im trying to test in web i have this error, the same DB, the same tables, the same data in both structures any idea????

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site244/fst/var/www/html/categoria.php on line 107

<?php
    require('conexion2.php');
    $SQLEmpresa= "SELECT empresa.cve_Empresa, Nombre, Direccion, pagina, telefono 
	             FROM empresa, empresa_Categoria  
		WHERE ".$_GET['cve_Categoria']." = empresa_Categoria.cve_Categoria 
		 AND empresa_Categoria.cve_Empresa = empresa.cve_Empresa";
    $rsEmpresa = mysql_query($SQLEmpresa,$conexion);
	$reg = array();
-->line 107	while ($reg = mysql_fetch_array($rsEmpresa))
	   {		
			$nombre =  $reg["Nombre"]; 
			$direccion =  $reg["Direccion"]; 
			$telefono =  $reg["telefono"]; 						
			$pagina = $reg["pagina"];
			$cve_Empresa = $reg["cve_Empresa"];	   					
?>
commented: Don't bump 5 year old threads. -1
commented: :( Bumping is very bad. -1

your query is failing for sure, echo the query and post it here.
or else execute the query directly inside the mysql and post ,if any error you got there

please help me...even i m getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 35

<?php $con = mysql_connect("localhost","root",""); if(!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("polling",$con); $result = mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] like '%$_POST[query]%'"); $found=0; [LINE 35]while($sri=mysql_fetch_array($result)) { if($sri['name']!="") { $found++; echo "&nbsp;&nbsp;&nbsp;&nbsp; ".$sri['name']."->".$sri['username']."<br />"; } } if($found!=0) {echo "Found ".$found." results!";} mysql_close($con) ?> [code/][code=php]
<?php
$con = mysql_connect("localhost","root","");
if(!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("polling",$con);
$result = mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] like '%$_POST[query]%'");
$found=0;
[LINE 35]while($sri=mysql_fetch_array($result))
{
if($sri!="")
{
$found++;
echo "&nbsp;&nbsp;&nbsp;&nbsp; ".$sri."->".$sri."<br />";
}
}
if($found!=0)
{echo "Found ".$found." results!";}
mysql_close($con)
?>
[code/]

your query doesnt seems right to me... try this

$query = "SELECT * FROM administrator WHERE".$_POST[searchby]."like  '%".$_POST[query]."%'";
$result = mysql_query($query);

always try to create n store ur query in a separate variable.. helps in debugging.
Hope this helps... cheers!!

please help me...even i m getting this error:
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 35

<?php
$con = mysql_connect("localhost","root","");
if(!$con)
  { 
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("polling",$con);
$result = mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] like '%$_POST[query]%'");
$found=0;
[LINE 35]while($sri=mysql_fetch_array($result))
{
 if($sri['name']!="")
 {
 $found++;
 echo "&nbsp;&nbsp;&nbsp;&nbsp; ".$sri['name']."->".$sri['username']."<br />";
 }
}
if($found!=0)
{echo "Found ".$found." results!";}
mysql_close($con)
?>

@venkat
doesnt help...now i am getting an parse error in the line select * .......

are you sure of the syntax in the sql query??
one more thing....$_post[query] ... returns the string entered in a search box named query.....

ohhh m so sorry... didn't include the spaces.. my bad.
just add a space after "where" clause and before "like".
should be--

$query = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like  '%".$_POST[query]."%'";

n do make sure that ur "searchby" parameter feeds the column name exactly as in ur table..(upper n lower case are considered different)

try this n lemme know..
cheers!!

@venkat
doesnt help...now i am getting an parse error in the line select * .......

are you sure of the syntax in the sql query??
one more thing....$_post[query] ... returns the string entered in a search box named query.....

The prob. is still there....anyway the search functionality is working well....the only thing is that the warning msg doesnt look good....and when i do the first search by entering a query....i get the search results and the error msg disappears...

well if ur search function is working fine then i guess the problem is with some other line...
why dont u post up the exact warning message and the code which is throwing it...

The prob. is still there....anyway the search functionality is working well....the only thing is that the warning msg doesnt look good....and when i do the first search by entering a query....i get the search results and the error msg disappears...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 38....and the code is same as above....Does the name of the file make any difference in PHP.for instance saving a file as loginpage.php or login_page.php

well i cant see a line 38 in ur code... it ends in 21 lines... i believe u r posting only half of the file...
and as far as names are concerned it wont make any difference unless u r using dose names to refer to those files from within ur code. Its not a gr8 practice to change file names after u have started writing code in them. just determine what that file is meant to do beforehand and name it accordingly...
For now i will suggest u to post the full code u have written in admin_loggedin_search_admin.php file

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 38....and the code is same as above....Does the name of the file make any difference in PHP.for instance saving a file as loginpage.php or login_page.php

Try this.

$query = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE  "%'.mysql_real_escape_string($_POST['query']).'%"';
mysql_query($query) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());

Also with the above code it should have a pretty good debugging error if it fails. So run the above script and tell me what the new error is if any.

now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Search for Administrators</title>
</head>

<body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">

<table width="1080">

<tr>

        
    <td width="710">
    <p>Search For Administrators
    <hr size="1">         <p/>
		 <form action="admin_loggedin_search_admin.php" method="post">
         Search by :
           <select name="searchby">
                      <option value="" SELECTED>-Select One-</option>
                      <option value="name" >Name</option>
                      <option value="state">State</option>
                      <option value="username">Username</option>
           </select>
		   <input type="text" name="query" size="10" maxlength="100" >  
           <input type="submit" name="submit" value="submit">
 <?php
$con = mysql_connect("localhost","root","");
if(!$con)
  { 
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("polling",$con);
$query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like  '%".$_POST[query]."%'";
$result = mysql_query($query1);
//$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" );
//$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
//mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
$found=0;
while($sri=mysql_fetch_array($result))
{
 if($sri['name']!="")
 {
 $found++;
 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
 }
}
if($found!=0)
{echo "<br />Found ".$found." results!";}


/*if(!mysql_query($sri,$con))
{
 die('Error: '.mysql_error());
}*/
mysql_close($con)
?>
 
<td width="270">
<td width="170">
<p>Search For
<hr size="1">
</p>
<a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
<p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
<p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>

<tr/>
</table>
</body>
</html>

now line 38 is line 40...save code as any xyz.php....modify form action as xyz.php and u can see the error...

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\admin_loggedin_search_admin.php on line 40

Try this:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Search for Administrators</title>
</head>

<body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">

<table width="1080">

<tr>

        
    <td width="710">
    <p>Search For Administrators
    <hr size="1">         <p/>
		 <form action="admin_loggedin_search_admin.php" method="post">
         Search by :
           <select name="searchby">
                      <option value="" SELECTED>-Select One-</option>
                      <option value="name" >Name</option>
                      <option value="state">State</option>
                      <option value="username">Username</option>
           </select>
		   <input type="text" name="query" size="10" maxlength="100" >  
           <input type="submit" name="submit" value="submit">
 <?php
$con = mysql_connect("localhost","root","");
if(!$con)
  { 
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("polling",$con);
$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
$found=0;
while($sri=mysql_fetch_array($result))
{
 if($sri['name']!="")
 {
 $found++;
 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
 }
}
if($found!=0)
{echo "<br />Found ".$found." results!";}


/*if(!mysql_query($sri,$con))
{
 die('Error: '.mysql_error());
}*/
mysql_close($con)
?>
 
<td width="270">
<td width="170">
<p>Search For
<hr size="1">
</p>
<a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
<p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
<p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>

<tr/>
</table>
</body>
</html>

There you go... the prob is not in the query statement bt its about the post variables... when the page loads for first time u dont have any values in ur post variables and thus it returns an error which gets disappeared as soon as u try searching because then u have some values in post.

So the solution for this is to place ur database access section inside an if statement which will enable search in database only when u ve got values in post variables.. something like this..

if(!empty($_POST['searchby']) && !empty($_POST['query'])){
$query1 = "SELECT * FROM user_tbl WHERE ".$_POST['searchby']." like  '%".$_POST['query']."%'";
$result = mysql_query($query1);
$found=0;

while($sri=mysql_fetch_array($result))
{
 if($sri['name']!="")
 {
 $found++;
 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
 }
}
if($found!=0)
{echo "<br />Found ".$found." results!";}
 
}

This should solve ur problem..
Cheers !!

now the search functionality has failed.....error:
SQL Syntax Error - query was:

Unknown column '' in 'where clause'


code is

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
	<title>Search for Administrators</title>
</head>

<body bgcolor="#FF9900" text="#FFFFCC" link="#FFFFFF" vlink="#FF3300" alink="#FFFF00">

<table width="1080">

<tr>

        
    <td width="710">
    <p>Search For Administrators
    <hr size="1">         <p/>
		 <form action="admin_loggedin_search_admin.php" method="post">
         Search by :
           <select name="searchby">
                      <option value="" SELECTED>-Select One-</option>
                      <option value="name" >Name</option>
                      <option value="state">State</option>
                      <option value="username">Username</option>
           </select>
		   <input type="text" name="query" size="10" maxlength="100" >  
           <input type="submit" name="submit" value="submit">
 <?php
$con = mysql_connect("localhost","root","");
if(!$con)
  { 
  die('Could not connect: ' . mysql_error());
  }
mysql_select_db("polling",$con);
$query1 = "SELECT * FROM administrator WHERE ".$_POST[searchby]." like  '%".$_POST[query]."%'";
$result = mysql_query($query1);
//$result=mysql_query("SELECT * FROM administrator WHERE $_POST[searchby] LIKE '%$_POST[query]%'" );
//$query1 = 'SELECT * FROM `administrator` WHERE `'.mysql_real_escape_string($_POST['searchby']).'` LIKE "%'.mysql_real_escape_string($_POST['query']).'%"';
//mysql_query($query1) or die('SQL Syntax Error - query was: <u>'.$query.'</u><hr>'.mysql_error());
$found=0;
while($sri=mysql_fetch_array($result))
{
 if($sri['name']!="")
 {
 $found++;
 echo "<br />&nbsp;&nbsp;&nbsp;&nbsp;".$sri['name']."->".$sri['username'];
 }
}
if($found!=0)
{echo "<br />Found ".$found." results!";}


/*if(!mysql_query($sri,$con))
{
 die('Error: '.mysql_error());
}*/
mysql_close($con)
?>
 
<td width="270">
<td width="170">
<p>Search For
<hr size="1">
</p>
<a href="admin_loggedin_search_voter.php" title="Search for Voters" >Voters</a>
<p><a href="admin_loggedin_search_candidate.php" title="Search for Candidates" >Candidates</a></p>
<p><a href="admin_loggedin_search_officer.php" title="Search for Officers" >Officers</a></p>

<tr/>
</table>
</body>
</html>

edit: I just noticed in ur statement u have missed single quotes while accessing the post variables... i wonder how u didnt get an error fr that!!

yes...got it!!I should have understood that...my problem is solved guys!!Thank you all for the patience you have showed...
@venkat...when i missed the single quotes i didnt get any error and the search func. is working fine..even i dont know how it happened....anyways...thanks again for your co-operation.

kool... all well that ends well :)

yes...got it!!I should have understood that...my problem is solved guys!!Thank you all for the patience you have showed...
@venkat...when i missed the single quotes i didnt get any error and the search func. is working fine..even i dont know how it happened....anyways...thanks again for your co-operation.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.