krysco Posted December 31, 2008 Share Posted December 31, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/ Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 You are not selecting a database...mysql_select_db after the connections is opened. Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726972 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 it's mysql_num_rows() NOT mysql_numrows() Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726975 Share on other sites More sharing options...
bluesoul Posted December 31, 2008 Share Posted December 31, 2008 Actually I believe mysql_numrows will work. Make sure to append your mysql_query() with or die(mysql_error());. Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726977 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 it's mysql_num_rows() NOT mysql_numrows() Both work =) mysql_numrows Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726978 Share on other sites More sharing options...
krysco Posted December 31, 2008 Author Share Posted December 31, 2008 premiso you were right i forgot to select the db thanx! Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726982 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 it's mysql_num_rows() NOT mysql_numrows() Both work =) mysql_numrows Awesome... Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726983 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 premiso you were right i forgot to select the db thanx! *Bows* (Please mark the thread as solved bottom left hand corner) Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726986 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 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!" Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726990 Share on other sites More sharing options...
premiso Posted December 31, 2008 Share Posted December 31, 2008 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!!! Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726992 Share on other sites More sharing options...
Maq Posted December 31, 2008 Share Posted December 31, 2008 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* Quote Link to comment https://forums.phpfreaks.com/topic/139004-php-trouble/#findComment-726995 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.