Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
PHP script giving 500 internal server error?
Old 01-18-2011, 02:00 PM PHP script giving 500 internal server error?
Experienced Talker

Posts: 40
Name: Andrew Benson
Trades: 0
This code produces no PHP fatal errors or warnings, but gives us an Apache 500 Internal Server error.
Why? I commented out pretty much the entire loop. If I comment out the first while too, it doesn't give a server error. But just with the while statement (and technically nothing happening inside it), it freaks out. What's goin on?

PHP Code:
<?php
 
// Connects to your Database 
 
require("libraries/db/dbconnect.php"); 
 
// Encrypt Page
 
require("libraries/auth/membersarea.php"

$username 
$_COOKIE['ID_my_site'];
$userID mysql_result(mysql_query("select ID from users where username = '$username'"), 0);

$result mysql_query("SELECT * FROM payroll ORDER BY PID DESC");
 
 if (!
$result) {
     echo 
"Could not successfully run query from DB: " mysql_error();
     exit;
     }
 if (
mysql_num_rows($result) == 0) {
     echo 
"No past payments available";
     exit;
     }
    
// New code by Josh
// Gonna annotate this like a boss to keep track

// Open our table up
    
echo "<table align=\"center\" width=\"400\">\r\n";
    
while(
$row mysql_fetch_array(mysql_query("SELECT * FROM payroll ORDER BY PID DESC")))
    {
    
// Table is opened. Let's bring in our Timestamp:
    //echo "<tr><td>Timestamp</td><td>".$row2['time…
    // Configure the columns of the table
    //echo "<tr><td></td><td><strong>Unit</strong><…
    // Bring in our variables now    
    /*while($row2 = mysql_fetch_array(mysql_query("SELECT * FROM vars ORDER BY ID ASC")))
        {
        // Determine variables
        $aliasName = $row2['varAlias'];
        $aliasRate = $row2['varAlias']."_rate";
        // Parse into table
        echo "<tr><td>".$aliasName."</td><td>".$row[$…
        }*/
    
}

    echo 
"</table>\r\n";
    
// End table

    
 // Footer Template
 
require("template/footer.php");
 
?>
djab is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-18-2011, 02:05 PM Re: PHP script giving 500 internal server error?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Before i even look over your code.

What errors do you get in your apache / webserver error.log?
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 01-18-2011, 02:07 PM Re: PHP script giving 500 internal server error?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
Is this meant to be like this?

Not having a ); at the end?
// Encrypt Page
require("libraries/auth/membersarea.php"
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 01-18-2011, 02:07 PM Re: PHP script giving 500 internal server error?
Novice Talker

Posts: 11
Name: Ed
Location: Gutemala City
Trades: 0
what if you test section by section,
in order to split the code in several sets of code, try it!
mckain is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 02:22 PM Re: PHP script giving 500 internal server error?
Experienced Talker

Posts: 40
Name: Andrew Benson
Trades: 0
PHP Code:
<?php
 
// Connects to your Database 
 
require("libraries/db/dbconnect.php"); 
 
// Encrypt Page
 
require("libraries/auth/membersarea.php");

$username $_COOKIE['ID_my_site'];
$userID mysql_result(mysql_query("select ID from users where username = ".$username.""), 0);

$result mysql_query("SELECT * FROM payroll ORDER BY PID DESC");
 
 if (!
$result) {
     echo 
"Could not successfully run query from DB: " mysql_error();
     exit;
     }
 if (
mysql_num_rows($result) == 0) {
     echo 
"No past payments available";
     exit;
     }
    
// New code by Josh
// Gonna annotate this like a boss to keep track

// Open our table up
    
echo "<table align=\"center\" width=\"400\">\r\n";
    
while(
$row mysql_fetch_array(mysql_query("SELECT * FROM payroll ORDER BY PID DESC")))
    {
    
// Table is opened. Let's bring in our Timestamp:
    
echo "<tr><td>Timestamp</td><td>".$row2['timestamp']."</td><td><i>N/A</i></td></tr>";
    
// Configure the columns of the table
    
echo "<tr><td></td><td><strong>Unit</strong></td><td><strong>Rate</strong></td></tr>\r\n";
    
// Bring in our variables now    
    
while($row2 mysql_fetch_array(mysql_query("SELECT * FROM vars where ID = ".$userID." ORDER BY ID ASC")))
        {
        
// Determine variables
        
$aliasName $row2['varAlias'];
        
$aliasRate $row2['varAlias']."_rate";
        
// Parse into table
        
echo "<tr><td>".$aliasName."</td><td>".$row[$aliasName]."</td><td>".$row[$aliasRate]."</td></tr>\r\n";
        }
    }

    echo 
"</table>\r\n";
    
// End table

    
 // Footer Template
 
require("template/footer.php");
 
?>
That is my code now. I have this in my error log about 1000 times.
Code:
[18-Jan-2011 14:18:25] PHP Warning:  mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/area51/public_html/RAI/secure/viewpastpayments.php on line 34
djab is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 02:29 PM Re: PHP script giving 500 internal server error?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I would suggest avoiding putting the sql query inside the while evaluation. It would be better to refer to a resource handler var
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 03:01 PM Re: PHP script giving 500 internal server error?
lynxus's Avatar
Awesomeo-Maximo

Posts: 1,618
Location: UK
Trades: 1
What happens if you simply change

while($row2 = mysql_fetch_array(mysql_query("SELECT * FROM vars where ID = ".$userID." ORDER BY ID ASC"))

to ( removing the ". and ." )

while($row2 = mysql_fetch_array(mysql_query("SELECT * FROM vars where ID = '$userID' ORDER BY ID ASC"))
__________________

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE


lynxus is offline
Reply With Quote
View Public Profile Visit lynxus's homepage!
 
Old 01-18-2011, 03:04 PM Re: PHP script giving 500 internal server error?
Experienced Talker

Posts: 40
Name: Andrew Benson
Trades: 0
I tried this instead.
PHP Code:
<?php
 
// Connects to your Database 
 
require("libraries/db/dbconnect.php"); 
 
// Encrypt Page
 
require("libraries/auth/membersarea.php");

$username $_COOKIE['ID_my_site'];
$userID mysql_result(mysql_query("select ID from users where username = '$username'"), 0);

// New code by Josh
// Gonna annotate this like a boss to keep track

// Open our table up
    
echo "<table align=\"center\" width=\"400\">\r\n";
// Configure the columns of the table
    
echo "<tr><td></td><td><strong>Unit</strong></td><td><strong>Rate</strong></td></tr>\r\n";
//SQL Query for the first while loop
    
$sql1 mysql_query("SELECT * FROM payroll where ID = ".$userID." and confirmed = '1' ORDER BY PID ASC");
//SQL Query for the second while loop
    
$sql2 mysql_query("SELECT * FROM vars ORDER BY ID ASC");
//If user has no payrolls    
 
if (mysql_num_rows($sql1) == 0) {
     echo 
"No past payments available";
     exit;
     }    
//First while loop
while($row mysql_fetch_array($sql1))
    {
    
// Table is opened. Let's bring in our Timestamp:
    // We'll put this on hold for now - echo "<tr><td>Timestamp</td><td>".$row2['timestamp']."</td><td><i>N/A</i></td></tr>";

    // Bring in our variables now    
    
while($row2 mysql_fetch_array($sql2))
        {
        
// Determine variables
        
$aliasName $row2['varAlias'];
        
$aliasRate $row2['varAlias']."_rate";
        
// Parse into table
        
echo "<tr><td>".$aliasName."</td><td>".$row[$aliasName]."</td><td>".$row[$aliasRate]."</td></tr>\r\n";
        }

    }
    echo 
"</table>\r\n";
    
// End table

    
 // Footer Template
 
require("template/footer.php");
 
?>

It does not give me any errors but it only shows the first row of the payroll table when in fact it needs to show every table that matches the $userID and has confirmed set to 1. Any ideas?
djab is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 03:11 PM Re: PHP script giving 500 internal server error?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You are reusing the same resource $sql2 for mysql_fetch_array() without redoing the query on it. I don't think that is allowed as the resource can only be looped once, I don't think it can be reset.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 03:13 PM Re: PHP script giving 500 internal server error?
Experienced Talker

Posts: 40
Name: Andrew Benson
Trades: 0
How would i fix it? What would the code look like?
djab is offline
Reply With Quote
View Public Profile
 
Old 01-18-2011, 03:16 PM Re: PHP script giving 500 internal server error?
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
PHP Code:
<?php
 
// Connects to your Database 
 
require("libraries/db/dbconnect.php"); 
 
// Encrypt Page
 
require("libraries/auth/membersarea.php");
$username $_COOKIE['ID_my_site'];
$userID mysql_result(mysql_query("select ID from users where username = '$username'"), 0);
// New code by Josh
// Gonna annotate this like a boss to keep track
// Open our table up
    
echo "<table align=\"center\" width=\"400\">\r\n";
// Configure the columns of the table
    
echo "<tr><td></td><td><strong>Unit</strong></td><td><strong>Rate</strong></td></tr>\r\n";
//SQL Query for the first while loop
    
$sql1 mysql_query("SELECT * FROM payroll where ID = ".$userID." and confirmed = '1' ORDER BY PID ASC");
//If user has no payrolls    
 
if (mysql_num_rows($sql1) == 0) {
     echo 
"No past payments available";
     exit;
     }    
//First while loop
while($row mysql_fetch_array($sql1))
    {
    
// Table is opened. Let's bring in our Timestamp:
    // We'll put this on hold for now - echo "<tr><td>Timestamp</td><td>".$row2['timestamp']."</td><td><i>N/A</i></td></tr>";
    // Bring in our variables now    
//SQL Query for the second while loop
    
$sql2 mysql_query("SELECT * FROM vars ORDER BY ID ASC");
    while(
$row2 mysql_fetch_array($sql2))
        {
        
// Determine variables
        
$aliasName $row2['varAlias'];
        
$aliasRate $row2['varAlias']."_rate";
        
// Parse into table
        
echo "<tr><td>".$aliasName."</td><td>".$row[$aliasName]."</td><td>".$row[$aliasRate]."</td></tr>\r\n";
        }
    }
    echo 
"</table>\r\n";
    
// End table
    
 // Footer Template
 
require("template/footer.php");
 
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 01-22-2011, 09:35 AM Re: PHP script giving 500 internal server error?
Banned

Posts: 23
Name: Pete Darren
Trades: 0
It could simply be that the host is down
dagaul102 is offline
Reply With Quote
View Public Profile
 
Old 01-22-2011, 09:51 AM Re: PHP script giving 500 internal server error?
Experienced Talker

Posts: 40
Name: Andrew Benson
Trades: 0
Thanks everyone. I tested it out. Mgrapgic's code works and doesn't give any errors. Thanks everyone again.
djab is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to PHP script giving 500 internal server error?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.39665 seconds with 12 queries