Help me!
Posted: Mon Apr 12, 2004 1:30 am
Hi guys,
I am having a little problem. I have a issuebook script for a library that records issue details- book_call_no, member_id, issue date. The issue table in the database has a column called return, which takes '0'; as default value when a new row is inserted, which indicates that the book is currently taken out by a member.
I am having a bit problem with my return.php script that handles the return of book. In this file I supply only two data - call_no, member_id and hit 'Accept' button.
The script then retrieves the return value matching the exact call_no and member_id [supplied in the return.php file] from the return table.
Like this:
if the result contains '1'
it says: echo "the book has already been returned";
here goes my full return.php script for better inspection.
I would appreciate if anybody can tell me why the result doesnot contain any value in it even though I supplied a valid call_no and a valid member_id that already exist in my issue table? I tried to echo the $result after I retrieve the return value but it does not display anything!. Why?
I am having a little problem. I have a issuebook script for a library that records issue details- book_call_no, member_id, issue date. The issue table in the database has a column called return, which takes '0'; as default value when a new row is inserted, which indicates that the book is currently taken out by a member.
I am having a bit problem with my return.php script that handles the return of book. In this file I supply only two data - call_no, member_id and hit 'Accept' button.
The script then retrieves the return value matching the exact call_no and member_id [supplied in the return.php file] from the return table.
Like this:
Code: Select all
<?php
$sql="SELEFT return FROM issue WHERE call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}'";
$result=mysql_query($sql);
if the result contains nothing
it says: echo " no record found";
if the result contains '0'
it runs this SQL statement:Code: Select all
<?php
$sql="UPDATE issue set return =1 WHERE call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}' && return =0";
$result=mysql_query($sql);
echo "Book Returned Successfully";
?>it says: echo "the book has already been returned";
here goes my full return.php script for better inspection.
I would appreciate if anybody can tell me why the result doesnot contain any value in it even though I supplied a valid call_no and a valid member_id that already exist in my issue table? I tried to echo the $result after I retrieve the return value but it does not display anything!. Why?
Code: Select all
<?php
<html>
<body>
<?php
if (isset($_POST['Accept'])) {
/* database connect script. */
require 'db_connect.php';
$sql="SELEFT return FROM issue WHERE call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}'";
$result=mysql_query($sql);
echo "$result"; //just to see what the $result variable contains.
if(!$result){
echo " no record found";
}
else if ($result==0){
//$sql="UPDATE issue set return =1 WHERE call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}' && return =0";
//$result=mysql_query($sql);
echo "Book Returned Successfully";
}
else if($result==1){
echo "the book has already been returned";
}
// process form
} else{
// display form
?>
<form method="post" action="<?php echo $PHP_SELF?>">
<td width="28%">Book Call No</td>
<td width="49%"><input type="text" name="call_no" size="20"></td>
<td width="28%">Member ID</td>
<td width="49%"><input type="text" name="mem_id" size="20"></td>
<p>
<input type="submit" value="Accept" name="Accept">
</p>
</form>
<?php
} // end if
?>
</body>
</html>
?>