2012-01-19 83 views
1

的原因不明。当我要求这个功能很奇怪,内部服务器错误

//Add the content to the database 
function articleadd() { 
    mysql_query("INSERT INTO site_content (title,content,reference,author,userid,authorip,day,month,year,token) VALUES ('$title','$articlebody','$reference','$author','$userid','$ipaddress','$day','$month','$year','$token')"); 
} 

对于它会产生一个内部服务器错误一些未知的原因。老实说,我不知道为什么,我要求低于这个功能,它工作正常

//Add a message if the user is not logged in 
function message() { 
mysql_query("INSERT INTO messages (from,to,subject,content,type,ip) VALUES ('$userid','$userid','The content $title is pending completion.','A article was attempted to be saved, however when the we tried to saved it there was no-one logged in. As a result we saved the article but quarantined it so it will not show on the website. To correct this error, please click the link below, review the article and confirm it should display on the site. <a href=$url>$url</a>','$type','$ipaddress')"); 

} 

与这两个我请求他们一前一后如下

articleadd() 
    message() 

我有,在它执行功能不能用一个非常简单的方法代替所有的mysql查询

echo "hello world"; 

但我得到的错误。

我试着复制和粘贴东西,即使是“功能”一词,以确保我不犯一个愚蠢的错误。不幸的是我没有访问与我的托管服务提供商的服务器日志。最后,我知道我没有传递变量,这是一个单独的问题,但是基于变量和“hello world”测试的工作原理,这不是问题。

+1

我得到担心,当我看到PHP函数的变量的值代码不使用[PHP Prepared Statements](http://php.net/manual/en/pdo.prepared-statements.php)来防止[SQL Injection](http://en.wikipedia.org/wiki/SQL_injection)漏洞。我希望你在这里没有粘贴的代码中清理你的变量。如果不是,请考虑重新编写代码以使用PDO Prepared Statements,而不是试图清理变量。 – sarnold 2012-01-19 00:09:03

+0

一个简单的['phpinfo()'](http://php.net/manual/en/function.phpinfo.php)脚本是否正确执行? – sarnold 2012-01-19 00:09:57

+1

如果'$ title'是'你不是逃避你的SQL'? **不要使用** mysql_query'函数。按照@sarnold的建议使用PDO。 – tadman 2012-01-19 00:11:56

回答

0

正如我所看到的,函数内部使用的变量没有值。 您需要设置如$用户ID,$作家,$标题从参数或全局变量

function articleadd($title,$articlebody,$reference,$author,$userid,$ipaddress,$day,$month,$year,$token) { 
mysql_query("INSERT INTO site_content (title,content,reference,author,userid,authorip,day,month,year,token) VALUES ('$title','$articlebody','$reference','$author','$userid','$ipaddress','$day','$month','$year','$token')");} 

而且这样调用

articleadd('title','articlebody','reference','author','userid','ipaddress','day','month','year','token');