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;
$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;
}
?>


<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>

<input type="Submit" value="Update">
</form>

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

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

or post your table structure..

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..

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

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

thanks..mark thread as solved

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

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..

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..

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...

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.

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

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

<?
$id=$_GET;
$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;
}
?>


<form action="updated.php" method="post">
<input type="hidden" name="ud_id" value="<? echo $id; ?>">
First Name: <input type="text" name="ud_first" value="<? echo $first; ?>"><br>
Last Name: <input type="text" name="ud_last" value="<? echo $last; ?>"><br>
Phone Number: <input type="text" name="ud_phone" value="<? echo $phone; ?>"><br>
Mobile Number: <input type="text" name="ud_mobile" value="<? echo $mobile; ?>"><br>
Fax Number: <input type="text" name="ud_fax" value="<? echo $fax; ?>"><br>

<input type="Submit" value="Update">
</form>

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.