2012-01-19 14 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')"); 
} 

を要求します。私は正直、私は下にこの機能を要求する理由は分からないし、それは私が持っている

articleadd() 
    message() 

を次のように両方の私が行う機能で、他の後にそれらを1つずつ要求AMで

//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')"); 

} 

正常に動作しますすべてのmysqlクエリを非常に単純なものに置き換えたものではありません。

echo "hello world"; 

エラーが発生しました。

私は愚かな間違いをしていないことを確認するために、「機能」という言葉をコピーして貼り付けることを試みました。残念ながら、私のホスティングプロバイダでサーバーログにアクセスすることはできません。最後に、私は変数を渡すのではなく、それは別の問題ですが、out変数と "hello world"テストで動作するということを基に、これは問題にはなりません。

+1

のような機能を呼び出す必要があります[SQL Injection](http://en.wikipedia.org/wiki/SQL_injection)を防ぐために[PHP Prepared Statements](http://php.net/manual/en/pdo.prepared-statements.php)を使用しないコード脆弱性私はここに貼り付けられていないコードであなたの変数を消毒することを願っています。そうでない場合は、変数をサニタイズするのではなく、PDO Prepared Statementsを使用するコードを書き直すことを検討してください。 – sarnold

+0

単純な['phpinfo()'](http://php.net/manual/en/function.phpinfo.php)スクリプトは正しく実行されますか? – sarnold

+1

'$ title'が'あなたのSQLをエスケープしていない 'ならばどうしますか? ** ** mysql_query関数を使わないでください。 @sarnoldが示唆するようにPDOを使用してください。 – tadman

答えて

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')");} 

から$タイトルのような変数の値を設定すると、私はPHPを見たとき、私は心配してもらうこの

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