1
我在我的網頁中有一個MySQL數據庫和php + js + jquery頁面。php從mysql獲取數據在服務器端產生500錯誤
在這個例子中瀏覽器加載一個PHP頁面與此內容:
<script type="text/javascript">
function MuestraNoticia(str)
{
if (str=="")
{
document.getElementById("rss_rcpt").innerHTML="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("rss_rcpt").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET","auth/peticion_noticia.php?page="+str,true);
xmlhttp.send();
}
MuestraNoticia(1);
</script>
<div id="rss_rcpt">
</div>
peticion_noticia.php
<?php
$event=$_GET["page"];
if($page == 1){
//allow sessions to be passed so we can see if the user is logged in
session_start();
//connect to the database so we can check, edit, or insert data to our users table
$con = mysql_connect('localhost', 'user', 'pwd') or die(mysql_error());
$db = mysql_select_db('dbname', $con) or die(mysql_error());
$SQL = "SELECT * FROM tablename";
$result = mysql_query($SQL);
echo "<table class='PaperPage'>";
echo "<tr>";
$GLOBALS['normalizeChars'] = array(
'Á'=>'Á', 'É'=>'É', 'Í'=>'Í', 'Ó'=>'Ó', 'Ú'=>'Ú', 'Ñ'=>'Ñ',
'á'=>'á', 'é'=>'é', 'í'=>'í', 'ó'=>'ó', 'ú'=>'ú', 'ñ'=>'ñ'
);
function arregla($toClean){
return strtr($toClean, $GLOBALS['normalizeChars']);
}
while ($row = mysql_fetch_array($result)) {
arregla($row['contenido']);
echo "<td class='PaperFechaData' style='width:100px'>" .$row['fecha']. "</td>";
echo "<td class='PaperTitData' style='width:820px'>" .$row['titulo']. "</td>";
echo "</tr><tr>";
echo "<td colspan='2' class='PaperCabData' style='width:920px'>". .$row['cabecera']. "</td>";
echo "</tr><tr>";
echo "<td class='PaperImgData'><img src='".$row['img']."' width='400px' height='400px'></td>";
echo "<td class='PaperTxtData' style='width:520px'>" .$row['contenido']. "</td>";
echo "</tr>";
echo "<tr><td colspan='2'></td></tr>";
}
echo "</table>";
mysql_close($con);
} else {
die();
}
?>
我有我的網頁的另一部分相同的代碼結構沒有任何問題,螺母在這種情況下瀏覽器返回HTTP/1.0 500內部服務器錯誤。
你檢查了php的錯誤日誌嗎? – DCoder 2012-04-22 19:13:32
我怎樣才能得到這個錯誤日誌。我不記得確切。 – 2012-04-22 19:20:45
看看'phpinfo()','error_log'設置的值將指向錯誤日誌文件的位置。 – DCoder 2012-04-22 19:22:40