0

I have two blocks of code in the body section of an html ( .php) document. The code block before my heading executes, but the block after the heading does not. I've tried phpinfo(); in the first block and it runs fine. Try it in the second block and it doesn't. I have no idea why this could be. If anyone has suggestions I'm all ears.

I'm currently running xampp on a windows machine.

<body>
<?php
if (isset($_SESSION['ProfileID'])){
    echo "<div style='text-align: right'>" 
    . "<a href='CZSN_Login.php'>Log " 
    . "Out</a></div>\n";
}
//here phpinfo() executes
?>
<h1>Chinese Zodiac Social Network</h1>
<?php
require_once("Includes/inc_ChineseZodiacDB.php");
//here phpinfo() will not execute
if (isset($_SESSION['ProfileID'])){
    echo "<h2>Member Pages</h2>\n"; 
echo"<p>Below is a list of the members of the Chinese Zodiac Social"
        . "Network. Click on a member's name to view that member's detailed information" 
        . "You may also choose to <a href='CZSN_MyProfile.php'>update your profile</a>.</p>\n";
    $SQLQuery="select first_name, last_name, user_name "
        . "from zodiac_profiles order by "
        . "last_name, first name, user_name;";
    $result=$DBConnect->query($SQLQuery);
    if ($result===false){
        echo $ErrorMsgs[];  
    }
    else{
        //This should never happen, but we can check anyway.
        if ($result->num_rows==0){
            echo "<p>There are no members to show.</p>\n";  
        }

Here is the code in my inc_ChineseZodiacDB.php file:

<?php
$ErrorMsgs = array();
$DBConnect = @new msqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
    $ErrorMsgs[] = "The database server is not available." 
        . "Connect Error is " 
        . $mysqli->connect_errno 
        . " " . $mysqli->connect_error . ".";
?>
11
  • did you get any error? to enable php error reporting, add error_reporting(E_ALL) and init_set('display_errors') top of your code and run your file. now, did you see any error? Commented Apr 20, 2014 at 23:44
  • No, I'm not getting any errors. The output is simply the h1 between the two code blocks. Commented Apr 20, 2014 at 23:47
  • you have said second block not executed, if you getting only <h1> markup then first block also not working. isn't? Commented Apr 20, 2014 at 23:52
  • phpinfo() will execute in the first block. right now the if statement will not evaluate true, so I used phpinfo() at the end of the first block to see if it would work, and it does. Commented Apr 20, 2014 at 23:56
  • @brock and if you comment the line require_once("Includes/inc_ChineseZodiacDB.php"); does it print the phpinfo? Commented Apr 21, 2014 at 0:02

4 Answers 4

1

Try searching in require_once ("Includes / inc_ChineseZodiacDB.php"); there can be triggered die() or exit();

Sign up to request clarification or add additional context in comments.

1 Comment

I don't have any die() or exit() statements in that file, but I did find the problem there.
0

I guess you get "Error headers already sent", because of the title <h1>Chinese Zodiac Social Network</h1>. For phpinfo() to work there shouldn't be any output yet.

1 Comment

phpinfo() works if I comment out the require_once statement.
0

You are closing the php tag in the inc_ChineseZodiacDB file (i.e. you have ?> at the end of that file).

When your first file reads in the inc_ChineseZodiacDB file and sees the ?>, it interprets that as the end of your php section of code, and all the other code after require_once("Includes/inc_ChineseZodiacDB.php"); is ignored and read as regular html.

Remove that line, and your problem should be fixed:

<?php
$ErrorMsgs = array();
$DBConnect = @new msqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
    $ErrorMsgs[] = "The database server is not available." 
        . "Connect Error is " 
        . $mysqli->connect_errno 
        . " " . $mysqli->connect_error . ".";

1 Comment

I removed the closing line and it behaves the same.
0

I figured out the ultimate problem. in the include file it reads:

<?php
$ErrorMsgs = array();
$DBConnect = @new msqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
    $ErrorMsgs[] = "The database server is not available." 
        . "Connect Error is " 
        . $mysqli->connect_errno 
        . " " . $mysqli->connect_error . ".";

?>

where it should read:

<?php
$ErrorMsgs = array();
$DBConnect = @new mysqli("localhost", "root", "password", "chinese_zodiac");
if ($DBConnect->connect_error)
    $ErrorMsgs[] = "The database server is not available." 
        . "Connect Error is " 
        . $mysqli->connect_errno 
        . " " . $mysqli->connect_error . ".";

?>

Note, I was calling msqli rather than mysqli. One simple typo...I'm still not understanding why the error messages were not being thrown for calling an undefined function. I added error_reporting(E_ALL); and ini_set('display_errors', 1); to the top of the file as well, and still no errors thrown. Either way, it works now. Thank you to everyone for the assistance.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.