Jump to content

Recommended Posts

This could be under ISS, PHP, or Mysql for all I know... so I posted here in the general PHP board.

I have a page that processes some user data that was working earlier yesterday but than suddenly stopped working and feeds me this error.

500 - Internal server error.

There is a problem with the resource you are looking for, and it cannot be displayed.

 

<?php require_once('../../Connections/Epm.php'); 
mysql_select_db($database_Epm, $Epm);?>
<?php include("../includes/functions.php");
check(); //User validation ?>
<?php
if(isset($_GET['A'] && $_GET['A'] == "pass"){
   if($_POST['password'] == $_POST['password2']){
      $sql = "UPDATE `bexusers` SET `Password`='p".md5($_POST['password'].$Salt)."' WHERE `Username`='".$_SESSION['Username']."'";
      $Update = mysql_query($sql, $Epm) or die(mysql_error());
      if(!isset(mysql_fetch_assoc($Update))){ die('Error: 10'); }
      header('Location: .././');
      } else { die('Passwords did not match'); }
   }
//FIND USER
  $colname_User = $_SESSION['Username'];
mysql_select_db($database_Epm, $Epm);
$query_User = sprintf("SELECT * FROM bexusers WHERE Username = '%s'", $colname_User);
$User = mysql_query($query_User, $Epm) or die(mysql_error());
$row_User = mysql_fetch_assoc($User);
$totalRows_User = mysql_num_rows($User);


if(isset($_POST['Pass']) && $_GET['A'] == "Try"){
   $Pass = "p".md5($_POST['Pass'].$Salt);
   if($Pass == $row_User['Password']){
      $_SESSION['ENC'] = md5($row_User['ID']); 
      header('Location: ../?P=User');}
   else {
   echo "The password was incorrect <br>"; }
   }
if($_GET['A'] == "un"){
   unset($_SESSION['ENC']);
   header('Location: ../?P=User');}


echo "Fail... no action specified.";
?>

 

Is there anything in the code that could cause that error?

OR

Is this a IIS problem?

OR

Is this a MySQL problem?

System info:

*Windows Server 2008

*IIS 7

*PHP 5.2.6

 

Link to comment
https://forums.phpfreaks.com/topic/130442-solved-unknown-cause-of-error/
Share on other sites

This is a 'catch-all' error generated by your Web server. Basically something has gone wrong, but the server can not be more specific about the error condition in its response to the client. In addition to the 500 error notified back to the client, the Web server should generate some kind of internal error log which gives more details of what went wrong.

 

To me this looks like a server error rather than a PHP or MySQL error. I say this because the error is so unspecific. if it was MySQL or PHP errors then the respective program would tell you, ie. you'd get a php syntax error etc...

Your code has a few errors from looking at it.

 

The first is on line 4:

if(isset($_GET['A'] && $_GET['A'] == "pass"){

 

It should be

if(isset($_GET['A']) && $_GET['A'] == "pass"){

 

The last error is on this line 10:

if(!isset(mysql_fetch_assoc($Update))){ die('Error: 10'); }

That code does not make sense. The line above is running an UPDATE query. No rows are returned from an update query so you cannot use mysql_fetch_assoc to check whether the query succeeded or not. You should use the mysql_affected_rows() function instead.

 

Your code fixed and cleaned

<?php require_once('../../Connections/Epm.php');
mysql_select_db($database_Epm, $Epm);?>
<?php include("../includes/functions.php");
check(); //User validation ?>
<?php
if(isset($_GET['A']) && $_GET['A'] == "pass")
{
    if($_POST['password'] == $_POST['password2'])
    {
        $sql = "UPDATE `bexusers` SET `Password`='p".md5($_POST['password'].$Salt)."' WHERE `Username`='".$_SESSION['Username']."'";
        $Update = mysql_query($sql, $Epm) or die(mysql_error());

        if(mysql_affected_rows($Update) != 0)
        {
            header('Location: .././');
        }
        else
        {
            die('Error: 10');
        }
    }
    else
        die('Passwords did not match');
}

//FIND USER
$colname_User = $_SESSION['Username'];
mysql_select_db($database_Epm, $Epm);
$query_User = sprintf("SELECT * FROM bexusers WHERE Username = '%s'", $colname_User);
$User = mysql_query($query_User, $Epm) or die(mysql_error());
$row_User = mysql_fetch_assoc($User);
$totalRows_User = mysql_num_rows($User);


if(isset($_POST['Pass']) && $_GET['A'] == "Try")
{
    $Pass = "p".md5($_POST['Pass'].$Salt);

    if($Pass == $row_User['Password'])
    {
        $_SESSION['ENC'] = md5($row_User['ID']);
        header('Location: ../?P=User');
    }
    else
    {
        echo "The password was incorrect <br>";
    }
}
elseif($_GET['A'] == "un")
{
   unset($_SESSION['ENC']);
   header('Location: ../?P=User');
}

echo "Fail... no action specified.";

?>

I got the page to start working again by reading exploring on google for at least two hours. Turns out I needed to change an .ini setting because I am using fast cgi and its on IIS.

But I was still having problems which what you just gave me will fix it... namely the mysql_affected_rows() because I found the missing ) a little bit ago once I got the page to start coming up again.

Thanks wild

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.