1

I can't understand why this PHP script gives me 500 internal server error.

$query = "SELECT video_id,title FROM video_id";
$videos = mysql_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?

pnuts
  • 58,317
  • 11
  • 87
  • 139
Shaps
  • 38
  • 1
  • 6

3 Answers3

4

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.

Vinko Vrsalovic
  • 330,807
  • 53
  • 334
  • 373
  • Googling a bit, it seems like SoftException in Application.cpp is suPHP. – Vinko Vrsalovic Oct 24 '10 at 22:16
  • yes, i found suPHP too, but i found the issue, Cyberduck was setting permissions to 666 while uploading to server. So it was group writable. I tried to change it in 755 and fixed the 666 of cyberduck and now the script is running. Thanks for answer. – Shaps Oct 25 '10 at 08:29
0

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.

DGM
  • 26,629
  • 7
  • 58
  • 79
0

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();
mellowsoon
  • 22,273
  • 19
  • 57
  • 75
  • Yes, thanks for helping me. I haven't had time to test the code, (cause 500 error). But now that i tested it i found those issues. Thanks for answering, Andrea. – Shaps Oct 25 '10 at 08:35