954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

update record error-mysql_numrows(): supplied argument is not a valid MySQL

Hi!, I am trying to update record but an error is coming. Can any one help.
error is - mysql_numrows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\xampp\Test\Report\Despatch\update.php on line 10
here is the script

<?
$id=$_GET['id'];
$username="root";
$password="mysql";
$database="service";
mysql_connect(localhost,$username,$password);

$query = "SELECT * FROM contacts WHERE id = '$id'";
$result = mysql_query($query);
$num = mysql_numrows($result);
mysql_close();

$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");

++$i;
}
?>



First Name:

Last Name:

Phone Number:

Mobile Number:

Fax Number:

san_cash
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

just echo this line and execute that query on your database area

$query = "SELECT * FROM contacts WHERE id = '$id'";


or post your table structure..

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 

hi,
problem is here you have forget to write (_)

$num = mysql_numrows($result);


change it to

$num = mysql_num_rows($result);


hope will help u..

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

ya exactly,, i even don't see this before..

Shanti C
Posting Virtuoso
1,642 posts since Jul 2008
Reputation Points: 137
Solved Threads: 162
 
ya exactly,, i even don't see this before..

thanks..mark thread as solved

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

hi, problem is here you have forget to write (_)

$num = mysql_numrows($result);

change it to

$num = mysql_num_rows($result);

hope will help u..


I tried but still the following errar is coming

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in C:\xampp\htdocs\xampp\Test\Report\Despatch\update.php on line 10

san_cash
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

If you are not setting password then left blank or write your password

$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }
		@mysql_select_db("service", $con);

$id=$_GET['id'];
echo $query = "SELECT * FROM contacts WHERE id = '$id'";
$result = mysql_query($query);
echo "num of rows".$num = mysql_num_rows($result);

check what result you get..

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

hi amith, i tried that too but still its telling the error.

hi, problem is here you have forget to write (_)

$num = mysql_numrows($result);

change it to

$num = mysql_num_rows($result);

hope will help u..

san_cash
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

If you are not setting password then left blank or write your password

$con = mysql_connect("localhost","root","");
	if (!$con)
	  {
	  die('Could not connect: ' . mysql_error());
	  }
	  else
	  {
	 // echo('Connected with Mysql');
	  }
		@mysql_select_db("service", $con);

$id=$_GET['id'];
echo $query = "SELECT * FROM contacts WHERE id = '$id'";
$result = mysql_query($query);
echo "num of rows".$num = mysql_num_rows($result);

check what result you get..

please check the post and tell me the result...

Aamit
Posting Whiz
342 posts since Apr 2008
Reputation Points: 3
Solved Threads: 15
 

You most likely have a problem with your query.
Replace:

$result = mysql_query($query);

with

$result = mysql_query($query) or die(mysql_error());

This will show the error.

kkeith29
Nearly a Posting Virtuoso
1,357 posts since Jun 2007
Reputation Points: 235
Solved Threads: 194
 

You are not selecting any database :) mysql_select_db("Databasename");

nav33n
Purple hazed!
Moderator
4,465 posts since Nov 2007
Reputation Points: 524
Solved Threads: 356
 

Amith, it says database not selected. Sorry but i am just started with learning php & mysql. following is the script

<?
$id=$_GET['id'];
$username="root";
$password="mysql";
$database="service";
mysql_connect(localhost,$username,$password);

$query = "SELECT * FROM contacts WHERE id = '$id'";
$result = mysql_query($query) or die(mysql_error());$result = mysql_query($query) or die(mysql_error());
$num = mysql_num_rows($result);
mysql_close();

$i=0;
while ($i < $num) {
$first=mysql_result($result,$i,"first");
$last=mysql_result($result,$i,"last");
$phone=mysql_result($result,$i,"phone");
$mobile=mysql_result($result,$i,"mobile");
$fax=mysql_result($result,$i,"fax");

++$i;
}
?>



First Name:

Last Name:

Phone Number:

Mobile Number:

Fax Number:

san_cash
Newbie Poster
10 posts since May 2009
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You