Help me!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Help me!

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

?>
Steveo31
Forum Contributor
Posts: 416
Joined: Sun Nov 23, 2003 9:05 pm
Location: San Jose CA

Post 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.
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post 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?
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

You need to use one of the _fetch functions, eg
$row = mysql_fetch_assoc($result);
echo $row['due_return_date'];
crazytopu
Forum Contributor
Posts: 259
Joined: Fri Nov 07, 2003 12:43 pm
Location: London, UK
Contact:

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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 :)
Post Reply