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
---
htmlheadtitleBook Update Form/title/head
body
?
$db=project;
$link = mysql_connect(localhost,name,passwd);
if (! $link)
die(Couldn't connect to MySQL);
mysql_select_db($db , $link)
or die(Couldn't open $db: .mysql_error());
$result = mysql_query( SELECT * FROM books )
or die(SELECT Error: .mysql_error());
$num_rows = mysql_num_rows($result);
print There are $num_rows records.P;
print table width=800 border=1\n;
while ($get_info = mysql_fetch_row($result)){
print tr\n;
foreach ($get_info as $field)
print \ttdfont face=arial size=2/$field/font/td\n;
print /tr\n;
}
print /table\n;
mysql_close($link);
//form method=POST action=book_change_form.php
?
br
form method=POST action=book_change_form.php
pre
Enter ISBN Number to Edit: input type=text name=id size=10
input type=submit value=Submitinput type=reset
/pre
/form
/body
/html
File 2
-
htmlheadtitleBook change form/title/head
body
?
$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);
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)
{
$isbn=mysql_result($result,$i,isbn);
$title=mysql_result($result,$i,title);
$author=mysql_result($result,$i,author);
$edition=mysql_result($result,$i,edition);
$course_id=mysql_result($result,$i,course);
$quantity=mysql_result($result,$i,quantity);
$stack_no=mysql_result($result,$i,stack_no);
?
table width=300 cellpadding=10 cellspacing=0 border=2
tr align=center valign=top
td align=center colspan=1 rowspan=1 bgcolor=#64b1ff
h3Edit 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 name=ud_id value=? echo $id ?
ISBN:input type=text name=ud_isbn value=? print
$isbn?br
Title: input type=text name=ud_title value=? print
$title?br
Author: input type=text name=ud_author value=? print
$author?br
Edition: input type=text name=ud_edition value=? print
$edition?br
Course Id: input type=text name=ud_course_id value=? print
$course_id?br
Quantity:input type=text name=ud_quantity value=? print
$quantity?br
Stack Number:input type=text name=ud_stack_no value=? echo
$stack_no?br
input type=Submit value=Update
/form
/td/tr/table
?
++$i;
}//end while
?
/body
/html
//
File 3
htmlheadtitleBook Change Record/title/head
body
?
$user=$_POST['username'];
$password=$_POST['password'];
$ud_id=$_POST['ud_id'];
$ud_isbn=$_POST['ud_isbn'];
$ud_title=$_POST['ud_title'];
$ud_author=$_POST['ud_author'];
$ud_edition=$_POST['ud_edition'];
$ud_course_id=$_POST['ud_course_id'];
$ud_quantity=$_POST['ud_quantity'];
$ud_stack_no=$_POST['ud_stack_no'];
$db=project;
$link = mysql_connect(localhost,name,passwd);
if (! $link)
die(Couldn't connect to MySQL);
mysql_select_db($db , $link)
or die(Couldn't open $db: .mysql_error());
mysql_query( UPDATE books SET isbn='$ud_isbn' ,title='$ud_title',
author='$ud_author',edition='$ud_edition',course_id='$ud_course_id',
quantity = '$ud_quantity', stack_no =
'$ud_stack_no'
WHERE isbn='$ud_id');
echo Record Updated;
mysql_close($link);
?
form method=POST action=book_update_form.php
input type=hidden name=username value=?php print
$_POST['username']?
input type=hidden name=pass value=?php print
$_POST['password']?
input type=submit value=Change Another
/formbr
form method=POST action=book.php
input type=hidden name=username value=?php print
$_POST['username']?
input type=hidden name=pass value=?php print
$_POST['password']?
input type=submit value=Book Interface
/form
/body
/html
-
Do you Yahoo!?
Yahoo! Tax Center - File online by April 15th