I'll start:

Pet's name: Malcolm
Owner's name: Tzatziki Cfnmpah IV
Code: Select all
<html>
<head>
</head>
<body>
<?php
define('IN_PHPBB', true);
$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
$phpEx = substr(strrchr(__FILE__, '.'), 1);
include($phpbb_root_path . 'common.' . $phpEx);
$user->session_begin();
if ($user->data['user_id'] == ANONYMOUS)
{
login_box('', $user->lang['LOGIN']);
}
require("adopttools.php");
/* Our visitor has picked an adoptable they want, its id is in $_REQUEST['id']. Find that
* adoptable in adoptables.xml
*/
$adoptable=find_adoptable($_REQUEST['id']);
/* To randomly pick a variation from that adoptable, we're going have to do a little maths with
* random numbers.
*
* First we find the sum of all the 'chance' attributes for this adoptable...
*/
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum=$sum + $variation['chance'];
}
/* Now we can generate a random number which goes from 0.0 to that sum. This will help us
* pick a variation.
*/
$random=lcg_value()*$sum;
$sum=0;
foreach ($adoptable->variation as $variation) {
$sum = $sum + $variation['chance'];
if ($random <= $sum) {
//Choose this variation
$v_id=$variation['id'];
break;
}
}
include "config.php";
// Create connection
try {
$conn = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpasswd);
// set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
// prepare sql and bind parameters
$stmt = $conn->prepare("INSERT INTO phpbb_exam (pet_type, pet_variation, pet_name, pet_owner) VALUES (:type, :variation, :name, :owner)");
$stmt->bindParam(':type', $type);
$stmt->bindParam(':variation', $v_id);
$stmt->bindParam(':name', $name);
$stmt->bindParam(':owner', $owner);
// insert a row
// set parameters and execute
$type = $_POST["id"];
$name = $_POST["petname"];
$owner = $user->data['user_id'];
$stmt->execute();
echo "Pet Adopted successfully";
}
catch(PDOException $e)
{
echo "Error: " . $e->getMessage();
}
$conn = null;
?>