PHP script results 500 Internal server error
I can't understand why this PHP script gives me 500 internal server error.
$query = "SELECT video_id,title FROM video_id";
$videos = mys开发者_开发知识库ql_query($query);
if($videos){
$videos = mysql_fetch_assoc($videos);
foreach($videos as $video){
echo '<div class="video">';
echo '<a href="video.php?v="'.$video['video_id'].'"> <h3>"'.$video['title'].'"</h3></a>';
echo '</div>';
}
}else{
echo "<p>No new videos actually</p>";
}
mysql_close();
?>
That's the code. It seems as every other simple script i wrote before. Watching the error log via cpanel i saw this error:
[Mon Oct 25 03:25:24 2010] [error] [client 80.181.111.60] SoftException in Application.cpp:256: File "/home/netatwor/public_html/cms/media/related.php" is writeable by group
Can anyone help me?
That's an error your webserver (or a frontend or module) is giving. It's checking permssions on the file /home/netatwor/public_html/cms/media/related.php
and it doesn't let it run because it is group writable.
To fix that, do chmod gw-w /home/netatwor/public_html/cms/media/related.php
, or the equivalent in what you use to handle permissions on your site.
I have no idea what Application.cpp is, but the error about being writable by group sounds like a security warning that your php file has the wrong permissions. Google for chmod
or uni file persissions.
Unrelated to your error, but I do believe your code is flawed on many levels, and wont be doing what you think it's doing. Let me show you:
$videos = mysql_fetch_assoc($videos);
foreach($videos as $video){
echo '<div class="video">';
echo '<a href="video.php?v="'.$video['video_id'].'"> <h3>"'.$video['title'].'"</h3></a>';
echo '</div>';
}
You may think that code is going to run for each video that is returned by the query, but it's not. You're actually foreach'ing over a single video, and that's it. The value of $video inside the foreach loop won't be an array. It will be the individual values within a single video array.
But there's more:
if($videos){
The value of mysql_query is either false, which means there was an error, or a resource pointing towards zero or more rows. It does not tell you if there were rows returned or not.
This is how your code should be written:
$query = "SELECT video_id,title FROM video_id";
$videos = mysql_query($query);
/**
* There was an error if $videos is false. Use mysql_error()
* to get a message explaining the error.
*/
if (!$videos) {
die(mysql_error());
}
/**
* You use the function mysql_num_rows() to find out how many
* rows were returned by the query.
*/
if(mysql_num_rows($videos) > 0) {
/**
* You need to keep calling mysql_fetch_assoc() until there are
* no more rows to return.
*/
while($video = mysql_fetch_assoc($videos)) {
echo '<div class="video">';
echo '<a href="video.php?v="'.$video['video_id'].'"> <h3>"'.$video['title'].'"</h3></a>';
echo '</div>';
}
} else {
echo "<p>No new videos actually</p>";
}
mysql_close();
精彩评论