【发布时间】:2014-01-06 03:25:14
【问题描述】:
我想要做的是让 mysql 数据库加载我的 .php 文件。我正在使用 hostgator 来运行 mysql 数据库服务器。到目前为止,我所拥有的 sql 是一个包含三列的表。
- int:id(主键/A.I.)
- varchar: 名称
- 文本:消息
我保存表并将其命名为“test”,数据库称为“testdb”
我的 php 文件(tutorialTest.php)如下所示:
<?php
$username = "nfoggia_nick";
$password = "imnick";
$database = "nfoggia_testdb";
mysql_connect(localhost, $username, $password);
@mysql_select_db($database) or die("Unable to find database");
$name =$_GET["name"];
$message = $_GET["message"];
$query = "INSERT INTO test VALUES (' ', '$name', '$message')";
mysql_querry($query) or die(mysql_error("error"));
mysql_close();
?>
我在 hostgator 的文件目录中添加了 .php 文件,现在我的问题是: 我知道这段代码什么都不做,但是当我输入时
http://localhost/tutorialTest.php
Web 浏览器显示“浏览器无法连接到本地主机”时它应该只显示一个空白屏幕。有什么帮助吗?我做错了什么?
编辑: 我将我的 php 文件移动到我网站的文档根目录,现在当我运行
http://myWebsiteName/tutorialTest.php this shows up:
Fatal error: Call to undefined function mysql_querry() in /home2/nfoggia/public_html/tutorialTest.php on line 15
【问题讨论】:
-
Please, don't use
mysql_*functions in new code。它们不再维护and are officially deprecated。看到red box?改为了解prepared statements,并使用PDO 或MySQLi - this article 将帮助您决定哪个。如果您选择 PDO,here is a good tutorial。仅供参考,您也对SQL injections 敞开心扉 -
你说的是hostgator,但url是loclahost?我很困惑
-
如果文件在某个 hostgator 服务器上,那么 URL 应该是您服务器的 URL,而不是 localhost
-
我不太明白,但我能找到的唯一原因是你在写,但是目录文件...检查一下
-
Localhost 是您的计算机。您的托管 URL 是什么?