当我单击我的PHP表单上的提交按钮时,我得到HTTP错误500.在localhost工作正常

时间:2017-05-05 13:52:39

标签: php server

我开始尝试使用php和数据库。当我在localhost上运行它时它完美无缺。信息写入数据库,一切都很好。当我将它传输到我的服务器并运行脚本时,我得到HTTP ERROR 500.此外,没有任何内容写入数据库表。 我将数据库信息更改为我的服务器数据库。我的服务器配置有问题吗?或者是代码?
Browser error pic

以下是代码:(create-account.php)

 <?php
include('classes/db.php');

if (isset($_POST['createaccount'])) {
    $username = $_POST['username'];
    $password = $_POST['password'];
    $email = $_POST['email'];

    DB::query('INSERT INTO users VALUES (\'\', :username, :password, :email)', array(':username'=>$username, ':password'=>$password, ':email'=>$email));
    echo "bravo";
}

?>


<h1>Register</h1>
<form action="create-account.php" method="post">
    <input type="text" name="username" value="" placeholder="Username ...">

    <input type="password" name="password" value="" placeholder="Password ...">

    <input type="email" name="email" value="" placeholder="someone@somesite.com">

    <input type="submit" name="createaccount" value="Create Account">

</form>

这是连接和查询代码(db.php):

    <?php 

class db {
    private static function connect() {
        $pdo = new PDO('mysql:host=ip;dbname=SocialNetwork;charset=utf8', 'root', 'password');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        return $pdo;
    }

    public static function query($query, $params = array()) {
        $statement = self::connect()->prepare($query);
        $statement->execute($params);
        //  $data = $statement->fetchAll();
        //  return $data;
    }
}

?>

这是日志中的最后一个错误,如果这也有帮助

[Fri May 05 13:48:33.828431 2017] [:error] [pid 16509] [client95.176.134.34:53373] PHP Fatal error:  Uncaught PDOException:SQLSTATE[HY000] [2002] Connection refused in/var/www/html/classes/db.php:5\nStack trace:\n#0 /var/www/html/classes/db.php(5): PDO->__construct('mysql:host=207....', 'root', 'password')\n#1 /var/www/html/classes/db.php(11): db::connect()\n#2 /var/www/html/create-account.php(9): db::query('INSERT INTO use...', Array)\n#3 {main}\n  thrown in /var/www/html/classes/db.php on line 5, referer: http://ip/create-account.php

0 个答案:

没有答案