I'm getting a fatal error, "Column cannot be null."
<head>
<script>
let xhr = window.XMLHttpRequest
? new XMLHttpRequest()
: new ActiveXObject('Microsoft.XMLHTTP')
xhr.open('POST', 'ajax.php', true)
xhr.setRequestHeader('content-type', 'applications/x-www-form-urlencoded')
xhr.send('sld=testing&tld=com®istrar=namecheap')
</script>
</head>
var_dump($_POST); // without these var_dumps
var_dump($_REQUEST); // i receive a 500 error (internal server error)
if ($_SERVER["REQUEST_METHOD"] === "POST"){
include "includes/connect_to_database.php";
$pdo = $connection->prepare("INSERT INTO domains (sld, tld, registrar) VALUES (:sld, :tld, :registrar)");
$pdo->execute(array(
":sld" => $_REQUEST["sld"],
":tld" => $_REQUEST["tld"],
":registrar" => $_REQUEST["registrar"]
));
$connection = null;
}
try {
$connection = new PDO("mysql:host=$dbhost; dbname=$dbname; charset=utf8", $dbuser, $dbpass);
$connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
echo "Connected successfully!";
} catch(PDOException $e) {
echo "Connection failed: " . $e->getMessage() . ".";
}

sld, so it's as if none of the data is being passed forward.responseText is also blank.$_POST too. var_dump($_REQUEST) and var_dump($_POST) return empty arrays in the response. encodeURIComponent on the post string, and that didn't work. var_dump statements.Could it be that I'm not sending all of the necessary headers?
What exactly am I doing wrong for the data not to be passed forward?
You are using wrong request header. Change it to
xhr.setRequestHeader('content-type','application/x-www-form-urlencoded')
instead of
applications/x-www-form-urlencoded
notice one 's' here.
I think you may not require
$_POST and $_REQUEST same time. So you may remove one of them.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With