-
My SQL Error
HI All
The problem I have got is that I got a table displaying results and I need to insert a form that allows you to update the code, but its displaying the following error code:Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in W:\www\Book\book_change_form.php on line 14. Its saying the error is with line 14 which I have highlighted, but read the forums and it doesnt necessarily refer to the room. Hope someone can help, many thanks
<html><head><title></title></head>
<body>
<?php
include("dbinfo.inc.php");
$comm=@mysql_connect(localhost,$username,$password);
$rs=@mysql_select_db($database) or die( "Unable to select database");
$id=$_POST['id'];
$sql="SELECT * FROM book WHERE Book_id='$id'";
//mysql_connect(localhost,$_POST['username'],$_POST['pass']);
$result=mysql_query($sql);
$num=mysql_num_rows($result);
$i=0;
while ($i < $num) {
$Title=mysql_result($result,$i,"Title");
$Cost=mysql_result($result,$i,"Cost");
$Stock=mysql_result($result,$i,"Stock");
?>
<table width="300" cellpadding="10" cellspacing="0" border="2">
<tr align="center" valign="top">
<td align="center" colspan="1" rowspan="1" bgcolor="#ffcc99">
<h3>Edit and Submit</h3>
<form action="book_change_record.php" method="post">
<input type="hidden" name="username" value="<?php print $_POST['username']?>">
<input type="hidden" name="pass" value="
<?php print $_POST['pass']?>">
<input type="hidden" Book_id="ud Book_id" value="<? echo "$Book_id" ?>">
Title: <input type="text" Title="ud_Title" value="<? print "$Title"?>"><br>
Cost: <input type="text" Cost="ud_Cost" value="<? echo "$Cost"?>"><br>
Stock: <input type="text" Stock="ud_Stock" value="<? echo "$Stock"?>"><br>
<input type="Submit" value="Update">
</form>
</td></tr></table>
<?
++$i;
}
?>
</body>
</html>
-
Re: My SQL Error
"but read the forums and it doesnt necessarily refer to the room" I'm not sure what that means or what it has to do with the problem.
As I see it, for what ever reason, it thinks that $result isn't a result set from a query.
I'm assuming you've read through this:
http://us2.php.net/manual/en/functio...l-num-rows.php
And the entry for mysql_query()
http://us2.php.net/manual/en/function.mysql-query.php
Particularly this:
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
Might want to make sure your query it executing correctly first.
-tg
-
Re: My SQL Error
Thanks for the advice. Have solved the error with the line 14 error. Whats happening now is when updating the requested record its saying the record has been updated but when going to view records its still showing old the original information.
-
Re: My SQL Error
You will have to show us the code from that page for us to be able to look into it. There is no update query on this page.
-
Re: My SQL Error
well, you're going to have to show some code for us to see what you might be doing wrong. you probably just have a bad UPDATE query. use [php] and [/php] tags to display code, too.
edit: had this page open from a few hours ago, didn't realize a reply was already made @_@.
-
Re: My SQL Error
Lol couldnt tell you how many times I have done that.