So I modified the script as I was instructed earlier, but I am still getting a blank page when I run the HTML form. What is wrong here?
所以我按照之前的指示修改了脚本,但是当我运行HTML表单时,我仍然得到一个空白页面。这有什么不对?
UPDATE 2: I get the following error now.
更新2:我现在收到以下错误。
Parse error: syntax error, unexpected T_VARIABLE in /home/content/o/m/o/omorgan/html/dimephysics/adviseme/ask.php on line 32
解析错误:语法错误,第32行/home/content/o/m/o/omorgan/html/dimephysics/adviseme/ask.php中的意外T_VARIABLE
<?php
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
//include('config.php');
//include('open_connection.php');
if (!isset($_POST['name']) || !isset($_POST['question']))
{
header ("Location: ask.html");
exit;
}
// Database parameters
$dbhost = '...';
$dbuser = 'questionme';
$dbpass = 'Question_2011';
$dbname = 'questionme';
$db_name = "questionme";
$table_name = "questions";
//Open connection
$connection = mysql_connect("", "questionme", "Question_2011")
or die(mysql_error());
$db = mysql_select_db($db_name, $connection) or die(mysql_error())
$name = mysql_escape_string($_POST[name]);
$question = mysql_escape_string($_POST[question]);
//Insert data into database
$sql = "INSERT INTO questions
(name, question) VALUES
('$name', '$question')";
?>
<html>
<head>
<title>Ask</title>
<head>
<body>
<h1>Question Submitted</h1>
<p><strong>Name:</strong>
<?php echo $_POST['name']; ?></p>
<p><strong>Question:</strong>
<?php echo $_POST['question']; ?></p>
</body>
</html>
7 个解决方案
#1
1
At a bare minimum you need quotes around your array indexes on this line:
至少,您需要在此行上的数组索引周围引用:
if (!isset($_POST[name]) || !isset($_POST[question]))
Make it
做了
if (!isset($_POST['name']) || !isset($_POST['question']))
Also, check your error level (can't give you a link at the moment, in a bit of a rush), PHP should be warning you about this.
另外,检查你的错误级别(暂时不能给你一个链接,有点急),PHP应该警告你这个。
#2
1
try changing
尝试改变
if (!isset($_POST[name]) || !isset($_POST[question]))
to
至
if (!isset($_POST['name']) || !isset($_POST['question']))
#3
1
Place this at the top of the script:
将它放在脚本的顶部:
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
This should let you know whats going on.
这应该让你知道发生了什么。
#4
0
Given your error message, it's obvious that your query is failing. You've supressed errors with @
on it, so the or die(...)
never kicks in.
鉴于您的错误消息,很明显您的查询失败。你已经用@来抑制错误,所以或者死(......)永远不会开始。
Your $table_name
in the query is undefined, so the query looks like
您的$ table_name在查询中是未定义的,因此查询看起来像
INSERT INTO (name, question) ...
which is incorrect SQL.
这是不正确的SQL。
The two major fixes you need:
您需要的两个主要修复:
- Remove the
@
supression on mysql_query(). It is almost NEVER acceptable to supress errors, particularly when dealing with a database. - 删除mysql_query()上的@ supression。压制错误几乎是不可接受的,特别是在处理数据库时。
- Define
$table_name
in your script, or change the variable inside the query string to a proper table name. - 在脚本中定义$ table_name,或将查询字符串中的变量更改为正确的表名。
#5
0
First of all, don't check with isset. Since $_POST is always generated you should be using !empty().
首先,不要用isset检查。由于$ _POST总是生成,所以你应该使用!empty()。
Remove @'s before mysql_* commands, this makes your script slow and suppresses helpful errors.
在mysql_ *命令之前删除@,这会使您的脚本变慢并抑制有用的错误。
And you are having issues because you don't have table variable set, $table_name needs to be defined.
而且由于您没有设置表变量,因此需要定义$ table_name。
If you are inserting questions to a table named 'questions' simply change your SQL to:
如果要将问题插入名为“questions”的表中,只需将SQL更改为:
//Insert data into database
$sql = "INSERT INTO `questions` (name, question)
VALUES ('$name', '$question')";
#6
0
You forgot add a semicolon *;* in line no. 30
你忘了在行号中加一个分号*; *三十
it should be
它应该是
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
instead of
代替
$db = mysql_select_db($db_name, $connection) or die(mysql_error())
#7
0
You need to end this line:
你需要结束这一行:
$db = mysql_select_db($db_name, $connection) or die(mysql_error())
change it to:
将其更改为:
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
#1
1
At a bare minimum you need quotes around your array indexes on this line:
至少,您需要在此行上的数组索引周围引用:
if (!isset($_POST[name]) || !isset($_POST[question]))
Make it
做了
if (!isset($_POST['name']) || !isset($_POST['question']))
Also, check your error level (can't give you a link at the moment, in a bit of a rush), PHP should be warning you about this.
另外,检查你的错误级别(暂时不能给你一个链接,有点急),PHP应该警告你这个。
#2
1
try changing
尝试改变
if (!isset($_POST[name]) || !isset($_POST[question]))
to
至
if (!isset($_POST['name']) || !isset($_POST['question']))
#3
1
Place this at the top of the script:
将它放在脚本的顶部:
ini_set('display_errors',1);
error_reporting(E_ALL|E_STRICT);
This should let you know whats going on.
这应该让你知道发生了什么。
#4
0
Given your error message, it's obvious that your query is failing. You've supressed errors with @
on it, so the or die(...)
never kicks in.
鉴于您的错误消息,很明显您的查询失败。你已经用@来抑制错误,所以或者死(......)永远不会开始。
Your $table_name
in the query is undefined, so the query looks like
您的$ table_name在查询中是未定义的,因此查询看起来像
INSERT INTO (name, question) ...
which is incorrect SQL.
这是不正确的SQL。
The two major fixes you need:
您需要的两个主要修复:
- Remove the
@
supression on mysql_query(). It is almost NEVER acceptable to supress errors, particularly when dealing with a database. - 删除mysql_query()上的@ supression。压制错误几乎是不可接受的,特别是在处理数据库时。
- Define
$table_name
in your script, or change the variable inside the query string to a proper table name. - 在脚本中定义$ table_name,或将查询字符串中的变量更改为正确的表名。
#5
0
First of all, don't check with isset. Since $_POST is always generated you should be using !empty().
首先,不要用isset检查。由于$ _POST总是生成,所以你应该使用!empty()。
Remove @'s before mysql_* commands, this makes your script slow and suppresses helpful errors.
在mysql_ *命令之前删除@,这会使您的脚本变慢并抑制有用的错误。
And you are having issues because you don't have table variable set, $table_name needs to be defined.
而且由于您没有设置表变量,因此需要定义$ table_name。
If you are inserting questions to a table named 'questions' simply change your SQL to:
如果要将问题插入名为“questions”的表中,只需将SQL更改为:
//Insert data into database
$sql = "INSERT INTO `questions` (name, question)
VALUES ('$name', '$question')";
#6
0
You forgot add a semicolon *;* in line no. 30
你忘了在行号中加一个分号*; *三十
it should be
它应该是
$db = mysql_select_db($db_name, $connection) or die(mysql_error());
instead of
代替
$db = mysql_select_db($db_name, $connection) or die(mysql_error())
#7
0
You need to end this line:
你需要结束这一行:
$db = mysql_select_db($db_name, $connection) or die(mysql_error())
change it to:
将其更改为:
$db = mysql_select_db($db_name, $connection) or die(mysql_error());