Jump to content

Recommended Posts

I have a small application that stores contact information into a MySQL database. I got the application working ok, it can insert information and display it perfectly. My problem is with the update process. I have it set up so that each entry is assigned a unique ID number and I use that number to do everything with the database entries. For the update page I get php to get the ID number from the URL, set it as a variable $id and use that variable in the script to select the correct entry. I don't think this is my problem. When I hit update from my display page its supposed to get the id and pass it to the update page to update the correct record. But when I hit the update link I get this error message : Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /var/www/tutorial/update.php on line 10. Based on this message it seems like something is wrong with the numrows command but I dont know what. I've used this exact command a million times in this application. HELP!

 

Display Page (page with update link)

<?
$username="root";
$password="catch2@";
$database="contacts";

mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query="SELECT * FROM contacts";
$result=mysql_query($query);

$num=mysql_numrows($result);
?>

<table border="0" cellspacing="2" cellpadding="2">
<tr>
<th><font face="Arial, Helvetica, sans-serif">Name</font></th>
<th><font face="Arial, Helvetica, sans-serif">Phone</font></th>
<th><font face="Arial, Helvetica, sans-serif">Mobile</font></th>
<th><font face="Arial, Helvetica, sans-serif">Fax</font></th>
<th><font face="Arial, Helvetica, sans-serif">E-mail</font></th>
<th><font face="Arial, Helvetica, sans-serif">" "</font></th>
</tr>

<?
$i=0;
while ($i < $num) {

$id=mysql_result($result,$i,"id");
$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");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
?>

<tr>
<td><font face="Arial, Helvetica, sans-serif"><? echo $first." ".$last; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $phone; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $mobile; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><? echo $fax; ?></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="mailto:<? echo $email; ?>">E-mail</a></font></td>
<td><font face="Arial, Helvetica, sans-serif"><a href="<? echo "./update.php?id=$id"; ?>">Update</a></font></td>
</form>
</tr>

<?
$i++;
}


echo "</table>";
?>

 

That page is supposed to pass a variable to this page to update the record:

<?php
$id=$_GET['id'];
$username="root";
$password="catch2@";
$database="contacts";
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");
$email=mysql_result($result,$i,"email");
$web=mysql_result($result,$i,"web");
?>

<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>
E-mail Address: <input type="text" name="ud_email" value="<? echo $email; ?>"><br>
Web Address: <input type="text" name="ud_web" value="<? echo $web; ?>"><br>
<input type="Submit" value="Update">
</form>

<?
++$i;
}
?>

 

But when the update link is clicked I get this error:

Warning: mysql_numrows(): supplied argument is not a valid MySQL result resource in /var/www/tutorial/update.php on line 10

 

Link to comment
https://forums.phpfreaks.com/topic/139004-php-trouble/
Share on other sites

premiso you were right i forgot to select the db thanx!

 

*Bows*

 

(Please mark the thread as solved bottom left hand corner)

 

*claps* "premiso, you're so smart!"

 

*blushes*  I did not expect a standing ovation!!!

 

I didn't stand...  *throws tomato*

Link to comment
https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726995
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.