user6559071 user6559071 - 4 months ago 8
SQL Question

apache2 and php - please advise

OK, I originally posted this a question about php, but have since realized it could be a server configuration problem, which I know little about. I left the php script in case, and am hoping someone might have some pointers on this - I already checked permissions (755).

"NetworkError: 500 Internal Server Error - http://localhost/register.php?name=uname&password=upassword"


I was hoping someone here would be able to catch my error - sorry if this is obvious I've been learning as I go.

<?php

define('USER', 'root');
define('PASS', 'password');



$dbh = new PDO('mysql:host=localhost;dbname=users', USER, PASS);

$uname = $_POST['uname'];
$upassword = password_hash($_POST['upassword'], PASSWORD_DEFAULT);

$query = 'INSERT INTO `users` (`name`, `password`) VALUES (?,?)';
$query->bind_param($uname, $upassword);



$queryResults = $dbh->prepare($query);
$queryResults->execute();

$queryResults = null;
$dbh = null; // close the connection


?>

This keeps giving me a 500 internal server error indicating the php script, (in firebug for firefox), and I can't really figure out where I'm going wrong. I can also post ajax if needed.

Answer

You are using a Query String http://localhost/register.php?name=uname&password=upassword". Its purely a GET Method.

Your have to check whether the GET Method is exist then you need to access the GET Method Data.

$uname = "";
if(isset($_GET['uname'])) {
    $uname = $_GET['uname'];
}

$upassword = "";
if(isset($_GET['password'])) {
    $upassword = $_GET['password'];
}

if(($uname != "") && ($upassword != "")) {
    $upassword = password_hash($upassword, PASSWORD_DEFAULT)

    $query = sprintf("INSERT INTO `users` (`name`, `password`) VALUES (%s, %s)", $uname, $upassword);

    ----- Statements ------
}
Comments