Page 1 of 1

Help me!

Posted: Mon Apr 12, 2004 1:30 am
by crazytopu
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:

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";

?>
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?




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> 

?>

Posted: Mon Apr 12, 2004 2:21 am
by Steveo31
$sql="SELEFT return FROM issue WHERE call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}'";
$result=mysql_query($sql);

Select is spelled wrong.

Posted: Mon Apr 12, 2004 2:43 am
by crazytopu
Thanks...but what about this one?

Code: Select all

<?php

$sql="SELECT due_return_date FROM issue WHERE  call_no= '{$_POST['call_no']}' && member_id='{$_POST['mem_id']}' && return =0";


$result=mysql_query($sql);

echo "$result";


?>
why do i get this result:

Code: Select all

Resource id #4
Instead of a date?

Posted: Mon Apr 12, 2004 2:56 am
by markl999
You need to use one of the _fetch functions, eg
$row = mysql_fetch_assoc($result);
echo $row['due_return_date'];

Posted: Mon Apr 12, 2004 7:18 am
by crazytopu
hi markl999

thanks for your help.

Just another little help that i need

Code: Select all

<?php

$due_return_date=12-3-04;
$actual_return_date=15-3-04;
?>

how do i find out how many days it exceeded? is there any built in function in php which helps me do it- subtracting one date from the other and find the number of days?





Thanks

Posted: Mon Apr 12, 2004 7:40 am
by patrikG
have a look at [php_man]mktime[/php_man] and [php_man]date[/php_man]. What you want to do is transform the both dates into a UNIX timestamp, compare them and tatatataaaaaa, there ya go :)