工作脚本停止工作(php,mysql)

时间:2017-06-30 06:20:46

标签: mysql database

我有一个奇怪的问题。 我在localhost上创建了一个网站。一切都很好。我可以毫无问题地连接到我的mysql数据库。 我决定将它放在外部服务器上,以便向朋友展示。我更改了$ username,$ dbname等。

然后我决定在localhost上使用该网站。然后它就开始了。当我运行我的脚本时,会向我的数据库(名称,消息,电子邮件)添加新记录,这会显示出来。

  

未选择数据库

在我决定将它放在服务器上之前,一切都和我一样。可能是什么问题?

编辑:这是connect.php的代码

<?php 

$username ="root";
$password = "";
$host = "localhost";
$table = "test";

$conn = new mysqli("$host", "$username", "$password", "$table");


if (!$conn) {
    die("Nie udało się połączyć z bazą danych: ".mysqli_connect_error());
}

这是一个在index.php中实现的脚本

        <?php
        include 'connect.php';


        $sql = "SELECT s_id, name, s_like, s_dislike, message FROM suggestions ORDER BY rand()";
        $result = mysqli_query($conn, $sql);


        $row = mysqli_fetch_assoc($result);

        $s_id = $row["s_id"];
        $s_like = $row["s_like"];
        $s_dislike = $row["s_dislike"];

        echo '<p>' . $row["message"] . '</p>';
        echo '<h1 class="podpis">' . $row["name"] . '</h1>';

        mysqli_close($conn);

        ?>

这里是comments.php的cde,其中我看到有关未选择数据库的消息。

    <?php

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$message = $_REQUEST['message'];

$username ="root";
$password = "";
$host = "localhost";
$table = "test";

$conn = mysqli_connect($host, $username, $password, $table);

$query = "INSERT INTO suggestions (name, email, message) VALUES ('$name', 
'$email', '$message')";

if (mysql_query($query)) {
    echo 'Dodano sugestię!';
    header('Location: index.php');
} else{ die(mysql_error());}

mysql_close();
?>

0 个答案:

没有答案
相关问题