Reputation: 327
I am trying to post data to my url but the form is not recognising anything being posted.
http://localhost/webpanel/createkeys.php?pcname=joe&username=guessme
so surely in the code below the $post values should be stored?
$_POST['pcname'];
$_POST['username'];
But when I load that url I posted I get this error:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'pcname' cannot be null' in
The rest of the code is posted below, it is a short php file but cannot work out the issue.
<?php
// if(!isset($_POST) || empty($_POST['pcname'])) {
// exit;
// }
$pcname = $_POST['pcname'];
$username = $_POST['username'];
include 'db.php';
$stmt = $connection->prepare('INSERT INTO dummy (pcname, username, privatekey) VALUES (?, ?, ?)');
$stmt->execute([
$pcname,
$username,
$privatekey
]);
Upvotes: 3
Views: 639
Reputation: 3318
$_GET, you bold use $_REQUEST which holds both but this is commonly bad practice.
You can simulate $_POST by performing a Curl request within php.
http://php.net/manual/en/book.curl.php
Upvotes: 1
Reputation: 10381
You have to use $_GET instead of $_POST :
$_GET['pcname'];
$_GET['username'];
Upvotes: 5