代码适用于本地服务器,但不适用于实时服务器

时间:2018-05-09 09:34:49

标签: php html5 debugging

此代码适用于本地服务器(XAMPP),但似乎不适用于实时服务器。而且我无法弄清楚问题是什么,因为错误日志中没有输出错误。 在脚本中,我尝试使用 - pre - tag但也没有显示任何内容

<?php session_start();?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <title>Testimony</title>
    </head>
    <body>
        <?php
        try {
            $linkas = 2;
            require_once 'db/DBConnect.php';
            $errors = [];
            $good = true;
            if ($_SERVER['REQUEST_METHOD'] == 'POST' && !empty($_POST['testimony'])):
                $testimony = /*filter_input(INPUT_POST, 'testimony', FILTER_SANITIZE_STRING)*/$_POST['testimony'];
                echo $testimony;
                if (strlen($testimony) < 20):
                    //report error and do not go
                    $errors[] = 'It has to be more than 20 characters' . '<br>';
                    $good = false;
                else:
                    echo $testimony;
                    $good = true;
                    if ($good):
                        $insertTestimony = 'INSERT INTO testimony(content, j_member_id) ';
                        $insertTestimony .= 'VALUES (:testimony, :user_id)';
                        $insert = $conn1->prepare($insertTestimony);
                        $insert->bindValue(':testimony', $testimony, PDO::PARAM_STR);
                        $insert->bindValue(':user_id', $linkas, PDO::PARAM_INT);
                        $insert->execute();
                        if ($insert->rowCount() == 1):
                            //success message
                            //$_SESSION['msg'] = 'Thanks for the testimony';
                            header('Location: index.php');
                        else:
                            //fail message
                            echo 'Something is wrong, please resubmit';
                        endif;
                    endif;
                endif;
            endif;
        } catch (Exception $e) {
            echo 'Database error: ' . $e->getMessage() . ' in ' . $e->getFile() . ':' . $e->getLine();
        }
        ?>
        <section class="">
            <article>
                <form action="" method="post" id="testimony" accept-charset="utf-8">
                    <fieldset>
                        <legend>Your testimony</legend>
                        <label for="testimony"></label>
                        <textarea id="testimony" name="testimony" maxlength="300"><?php
        if (isset($_POST['testimony'])):
            echo htmlspecialchars($testimony);
        endif;
        ?></textarea>
                    </fieldset>
                    <input type="submit" name="testify" id="testify" value="Testify">
                </form>
            </article>
        </section>
    </body>
</html>

这是我用来连接数据库的数据库连接字符串,它位于db文件夹

<?php
//Db connection 1
$username ="XXXXX"; // censored for SO
$password = "XXXXX"; // censored for SO
//$database = "xzelanet_180days";
//$server="localhost";
$conn1 = new PDO('mysql:host=localhost;dbname=xzeere_30days; charset=utf8', $username, $password);
$conn1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

表单提交后,表单拒绝插入数据库(显示的表单但不提交[我认为问题应该在处理表单的代码内部])

0 个答案:

没有答案