[英]What is wrong with my ask.php Syntax?
So I modified the script as I was instructed earlier, but I am still getting a blank page when I run the HTML form. 因此,我按照我之前的指示修改了脚本,但是运行HTML表单时仍然出现空白页。 What is wrong here?
这有什么不对?
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>
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应该为此警告您。
try changing 尝试改变
if (!isset($_POST[name]) || !isset($_POST[question]))
to 至
if (!isset($_POST['name']) || !isset($_POST['question']))
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. 这应该让您知道发生了什么事。
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. 您用
@
抑制了错误,因此or die(...)
永远不会起作用。
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: 您需要的两个主要修复程序:
@
supression on mysql_query(). @
supression。 It is almost NEVER acceptable to supress errors, particularly when dealing with a database. $table_name
in your script, or change the variable inside the query string to a proper table name. $table_name
,或将查询字符串中的变量更改为适当的表名。 First of all, don't check with isset. 首先,不要检查isset。 Since $_POST is always generated you should be using !empty().
由于总是生成$ _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')";
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())
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());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.