I have written a library program where a user can search for books. I am now onto the part where a user can select an item by it's ID and their own username. This then sets a a payment on PayPal for the user to approve. Now I've made a start but I'm quite lost. I get the book by its ID and fill use its details stored in the database - price and title to set up the payment.
The first issue I'm having is I get the following error:
Undefined index: book_id 
I get this error too for price, user and title.
Here is the code for the payment:
try {
      $dbh = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_USERNAME, DB_USERNAME, DB_PASSWORD);
} catch   (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
  $book =$_POST["book_id"];
  $user =$_POST["user"];
  $price =$_GET["price"];
  $title =$_GET["title"];
$sth = $dbh->prepare("SELECT title, price FROM books2 WHERE b_id=$book");
$sth->execute();
$payer = new Payer();
$payer->setPaymentMethod("paypal");
$item1 = new Item();
$item1->setName($title)
    ->setCurrency('USD')
    ->setQuantity(1)
    ->setPrice($price);
 $details = new Details();
 $details->setShipping(1.5)
     ->setTax(1.7);
$transaction = new Transaction();
$transaction->setAmount($price)
    ->setItemList($item1)
    ->setDescription("Payment description")
    ->setInvoiceNumber(uniqid());
$baseUrl = getBaseUrl();
$redirectUrls = new RedirectUrls();
$redirectUrls->setReturnUrl("$baseUrl/review.php?success=true")
    ->setCancelUrl("$baseUrl/payment.php?success=false");
$payment = new Payment();
$payment->setIntent("sale")
    ->setPayer($user)
    ->setRedirectUrls($redirectUrls)
    ->setTransactions(array($transaction));
    $execution = new PaymentExecution();
$result = $payment->execute($execution, $apiContext);
$request = clone $payment;
try {
    $payment->create($apiContext);
} catch (Exception $ex) {
    ResultPrinter::printError("Created Payment Using PayPal. Please visit the URL to Approve.", "Payment", null, $request, $ex);
    exit(1);
}
$approvalUrl = $payment->getApprovalLink();
ResultPrinter::printResult("Setting up payment using Paypal. Please visit the URL to Approve.", "Payment", "<a href='$approvalUrl' >$approvalUrl</a>", $request, $payment);
return $payment;
Can anyone tell why why I'm getting these errors so I can make this code work?
 
    