Location: PHPKode > projects > PHP-Comics > php-comics/ajax/bookmark.php
$comic = urldecode(stripslashes($_POST['comic']));
$path = urldecode(stripslashes($_POST['path']));

$BookID = DB::QueryResult("SELECT b.ID FROM Book b, Folder f WHERE f.ID = b.Folder AND f.Path = '$path' AND b.Name='$comic'",'ID',1);
if($BookID == null)
	//In the rare event that the book is not in the database, add it to the database

	//check the path first
	$FolderID = DB::QueryResult("SELECT f.ID From Folder f WHERE f.Path = '$path'","ID");
		DB::Query("INSERT INTO Folder (Path) VALUES ('$path')");
		$FolderID = mysql_insert_id();
	DB::Query("INSERT INTO Book (Folder,Name) VALUES($FolderID,'$comic')");
	$BookID = mysql_insert_id();
//Ok so now we have a book ID for sure. Now update/insert the bookmark
$time = time();
$page = $_POST['page'];
DB::Query("INSERT INTO Bookmark (Book,Page,Time,UID) VALUES ($BookID,'$page',$time,$_SESSION[UID]) ON DUPLICATE KEY UPDATE Page = '$page', Time = $time");
	DB::Query("UPDATE Bookmark SET IsRead = 1 WHERE Book = $BookID AND UID = $_SESSION[UID]");
echo "1";
Return current item: PHP-Comics