Re: [PHP-DB] Hi I am new to PHP

2004-04-15 Thread George Patterson
On Thu, 15 Apr 2004 14:58:09 -0700 (PDT)
andy amol <[EMAIL PROTECTED]> wrote:

> Hi,
>I have a problem with the second file. I am not able to update the 
> data from the php program. Any help on that would be appreciated. 
> Any modification which would be reduce the code like directly using
> the Update command would be appreciated.
>
> thanks in advance.
>  
> My exact problem with second file is as follows:
> 
> Warning: mysql_num_rows(): supplied argument is not a valid MySQL
> result resource on line 15

Andy, 
This is probably not the entire error message. The above error message would have 
shown the name of the php script that is broken. This would have made it easier for 
whoever
> 
> 
> Here are the 3 files.
> 
> File1
Looks okay...

> 
> File 2
> -
> Book change form
> 
>  $id=$_POST['id'];
> $db="project";
> //mysql_connect(localhost,$_POST['username'],$_POST['pass']);
> $link = mysql_connect("localhost","name","passwd");
> if (! $link)
> die("Couldn't connect to MySQL");

A better way to write this is 
> $link = mysql_connect("localhost","name","passwd") 
or die("Couldn't connect to MySQL");

> mysql_select_db($db , $link)
> or die("Couldn't open $db: ".mysql_error());
> $query=" SELECT * FROM books WHERE id='$id'";
> $result=mysql_query($query);
> $num=mysql_num_rows($result);
> //echo $num;
> $i=0;
> while ($i < $num)
> { 

This could be rewritten as
while ($row = mysql_fetch_assoc($result);) {
The reason wil soon become apparent.

Okay, using mysql_result() functions calls is expensive as far as resources go.

> $isbn=mysql_result($result,$i,"isbn");
Each of these lines change into similar to the following example line
echo $row["isbn"];

> $title=mysql_result($result,$i,"title");
echo $row["title"];
> $author=mysql_result($result,$i,"author");
echo $row["author"];
> $edition=mysql_result($result,$i,"edition");
echo $row["edition"];
> $course_id=mysql_result($result,$i,"course");
echo $row["course"];
> $quantity=mysql_result($result,$i,"quantity");
echo $row["quantity"];
> $stack_no=mysql_result($result,$i,"stack_no");
echo $row["stack_no"];

The reason for doing this is that each call to mysql_result() requires PHP to ask the 
MySQL server for the cell specified. Even if your web server and MySQL server is on 
the same machine, you will still notice a speed increase if you do just one fetch per 
row rather than a fetch per field in the row. You would use mysql_result() if you are 
wanting only one cell from a query result. 

Otherwise this the rest of the looks pretty good.

> ?>
> 
> 
> //
> File 3
> 
> Book Change Record
> 
>  $user=$_POST['username'];
> $password=$_POST['password'];
Move this line up to the other database connection values.

The rest of the file looks okay...

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-DB] Hi I am new to PHP

2004-04-15 Thread andy amol
Hi,
I have a problem with the second file. I am not able to update the 
data from the php program. Any help on that would be appreciated. 
Any modification which would be reduce the code like directly using the 
Update command would be appreciated.
thanks in advance.
 
My exact problem with second file is as follows:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on 
line 15


Here are the 3 files.

File1
---
Book Update Form

";
print "\n";
while ($get_info = mysql_fetch_row($result)){ 
print "\n";
foreach ($get_info as $field) 
print "\t$field\n";
print "\n";
}
print "\n";
mysql_close($link);
//
?>



Enter ISBN Number to Edit: 






File 2
-
Book change form





Edit and Submit



">
ISBN:">
Title:   ">
Author:  ">
Edition: ">
Course Id:   ">
Quantity:">
Stack Number:">






//
File 3

Book Change Record


















-
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th

[PHP-DB] Hi I am new to PHP

2004-04-15 Thread andy amol

I have posted my problem at No: 33892 of this mailing list. I have received 1 reply. 
No: 33897

My exact problem with second file is as follows:

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource on 
line 15


Can you help me to solve problem, any help would be appreciated.

Thanks.



-
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th