服务器获取请求失败

时间:2016-08-05 08:49:03

标签: php html mysql

我正在尝试设置一个基本网页,允许用户在数据库的mysql表中添加一行,以便使用arduino打开LED指示灯。但是,当我尝试提交表单时,页面返回500状态,并且不执行mysql查询。我在我的电脑上运行了一个linux-apache-mysql-php服务器。为什么会这样?

<!doctype html>
<html>
        <head>
                <title> ARDUINO CONTROL CENTER </title>
                <meta charset = "utf-8"/>
                <link rel = "stylesheet" type = "text/css" href = "#" />
        </head>
        <body>
                <h1> Welcome to the online arduino controller </h1>
                <p> From here you can actually control an arduino in my room that will turn an LED light on and off. </p>
                <form method = "get" action = "index.php">
                        <select name = "action">
                                <option value = "ON">ON</option>
                                <option value = "OFF">OFF</option>
                        </select>
                        <input type = "number" name = "duration"/>
                        <input type = "submit" />
                </form>
        </body>
</html>
<?php

        $host = 'localhost';
        $username = 'petros';
        $password = '**********'; //can't give my password
        $dbc = mysql_connect($host,$username,$password) or die("Unable to connect to server");

        $db = 'ledrequests';
        $sdb = mysql_select_db($db,$dbc) or die("Unable to connect to database.");

        if(isset($_GET['action']) && isset($_GET['duration'])){
                $action = $_GET['action'];
                $duration = $_GET['duration'];
                $query = "INSERT INTO requests(`act`,`duration`) VALUES ('$action',$duration)";
                mysql_query($query);
        }

?>

2 个答案:

答案 0 :(得分:0)

HTTP状态代码500是一个&#34;内部服务器错误&#34;因此,通过检查Apache错误日志,找出代码错误的适当位置。

如果你正在使用WAMP:Where can I find the WAMP error log?

如果你正在使用MAMP:https://sites.google.com/site/mamppro/en/mamp/faq/where-can-i-find-the-logs/where-can-i-find-the-apache-error-log

如果你只是喜欢linux的风格:/var/log/apache2/error.log

答案 1 :(得分:0)

它可能是从缺少PHP-MySQL扩展开始到以MySQL密码拼写错误和无效查询语法结束的任何地方。

让您的脚本在页面中查询输出或查看服务器的日志(如果它们可用)。

你应该在apache日志中找到我们可以帮助你的东西。