无论出于何种原因,每当我提交表单时,它都不会将输入的数据添加到数据库中。它之前正在工作......我认为最让我感到沮丧的是。几个小时后我回来了,惊喜!不将新行插入数据库。也许我偶然会意外地做了一个小错误?但是,没有什么比我更突出的了。 :(
refer.html:http://pastebin.com/d1xQUJLR
generator.php:http://pastebin.com/CE2UX8zs
main.js:http://pastebin.com/CSQh9DKs
答案 0 :(得分:1)
修复代码中的一些错误;)
<?php
include_once "access.php";
$ref_email = $_POST["tf_ref_email"];
$ref_username = $_POST["tf_ref_username"];
$ref_ign = $_POST["tf_ref_ign"];
$access = new Access();
$crux = $access->getCrux();
$anchor = $access->getAnchor();
$user = $access->getUser();
try {
$pdo = new PDO($anchor, $user, $crux);
$stq = "INSERT INTO referred_users
(ref_id, ref_email, ref_username, ref_ign, ref_awarded, new_email, new_awarded)
VALUES (:ref_id, :ref_email, :ref_username, :ref_ign, :ref_awarded, :new_email, :new_awarded)";
for($i = 0; $i < min(count($_POST["emails"]), 10); $i++) {
$ref_id = $_POST["ref_ids"][$i];
$new_email = $_POST["emails"][$i];
$new_ref_id = checkId($ref_id, $pdo);
$query = $pdo->prepare($stq);
$results = $query->execute(
array(
':ref_id' => $new_ref_id,
':ref_email' => $ref_email,
':ref_username' => $ref_username,
':ref_ign' => $ref_ign,
':ref_awarded' => '0',
':new_email' => $new_email,
':new_awarded' => '0'
)
);
$to = $new_email;
$subject = "Check out this AMAZING Minecraft RP Server!";
$message = "You have been invited to join " . $ref_ign . " in Arithia! Enter your Referral ID in the provided link to get a head start on your first character!" . "\n";
$message .= "Referral ID: " . $new_ref_id . "\n";
$message .= "Redeem Rewards: " . "http://www.graphicgoldfish.com/referral/referral.html" . "\n";
$message .= "By redeeming your referral, you will get:" . "\n";
$message .= "- 300 Credit Points" . "\n";
$message .= "- 50 Ducats" . "\n";
$message .= "- 25 Cooked Beef" . "\n";
$message .= "- Identification Tome" . "\n";
$message .= "We look forward to seeing you in Arithia! For more information, visit: http://www.arithia.com" . "\n";
$headers = "From: $ref_email";
mail($to, $subject, $message, $headers);
}
} catch(PDOException $e) {
echo 'Error: ' . $e->getMessage();
}
function checkId($id, $con) {
$stmt = $con->prepare("SELECT ref_id FROM referred_users WHERE ref_id = :ref_id");
$stmt->bindParam(':ref_id', $id);
$stmt->execute();
if($stmt->rowCount() > 0) {
$new_id = (string)rand(1000000, 9999999);
return checkId($new_id, $con);
}
return $id;
}