0

This php file will run perfect on it's own, but when it is called through ajax I get an unexpected eof error.

<?php

$servername = "localhost";
$username = "group10";
$password = "TWN6UmXjpVHhxNhM";
$dbName = "group10";
$formName = htmlspecialchars($_POST['name']);
$err = false;
$topID = 0;


$conn = new PDO('mysql:host=' . $servername . ';dbname=' . $dbName . ';charset=utf8', $username, $password);

//check for dupes
$query = "SELECT * FROM summoners ORDER BY id ASC";
$noSpace = str_replace(' ', '', $formName);
foreach ($conn->query($query) as $row) {
    if (str_replace(' ', '', $row['name']) === $noSpace) {
        echo json_encode("taken");
        $err = true;
    }
    $topID = $row['id'] + 1;
}

//insert name
if (!err) {
    try {
        $stmt = $conn->prepare("INSERT INTO summoners(id,name) VALUES(:id, :name)");
        $stmt->execute(array(
            "id" => $topID,
            "name" => $formName
        ));
        if ($stmt->rowCount() > 0) {
            echo json_encode("success");
        }
    } catch (Exception $ex) {
        echo json_encode("sqlerr");
    }
}
$conn = null;

Any help in this matter would be greatly appreciated.

  • What is the **exact** error message and where are you seeing it? – Phil Dec 02 '14 at 23:57
  • In the netbeans output log, I either get this error: Failed to load resource: Software caused connection abort: recv failed (19:04:09:778 | error, network) at public_html/submit.php or this error: Failed to load resource: Unexpected end of file from server: recv failed (19:04:09:778 | error, network) at public_html/submit.php – user4298098 Dec 03 '14 at 00:18

0 Answers0