2

I'm currently working on a website (a quiz), but have run into a somewhat strange issue where my php code is not displaying after a certain point. I'll also note that while I am a student, this is for a research project that I was given express permission from my advisor to post about.

http://zephyr.sista.arizona.edu/learn2cal/index The issue itself is on the /quiz.php page, but that will give you server errors if you try to access it without going through the start page first.

My own code looks something like this:

<?php
require_once("./databaseAdaptor.php");

$page = '0';
if(isset($_POST["page"])) {
$page = $_POST["page"];
} else {
 echo "";
$page = '1';
}

if(isset($_POST['user'])) {
$user = $_POST['user'];
} else {
    echo "error";
}
echo $user;
echo $page;


?>
    
<!DOCTYPE HTML5>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <title>FOOD CALORIES</title>
 <link rel="stylesheet" href="css/styles.css"/>
</head>

<body>
    
    <div>
        <h4><a href="index.html">Calorie4Food</a></h4>
    </div>

    <article>
        <center>
            <h5>How many calories are in the food pictured here? </h5>
            <h6>(Type a number in the box)</h6>

   <!-- progress bar -->
            <num>Progress Bar</num>
            <label2><progress id="pro" value="<?=($page-1)*(10/3) ?>" max="100"></progress></label2>
            <num id="num"><?=floor(($page-1) * (10/3)) ?></num> <num>%</num>
            <br><br>
            

            <?php
            require_once("/databaseAdaptor.php");
            $image = $myDatabaseFunctions->getImage(1)[0];
            $imageIDArray = explode("/", $image);
            $imageID = $imageIDArray[1];
           
            ?>

            <img src="./<?=$image?>.jpg" alt=""/>
            
   
  <section>
                <form method="post" action="./reinforce.php" onsubmit="checkform()">
                    <input type="number" name="estimate" value="quizInput"/> 
                        <word>cal</word> 
                    <input type='hidden' name='start' value='<?=date('Y-m-d G:i:s')?>'>
                    <input type='hidden' name='imageID' value='<?=$imageID?>'>
     <input type="hidden" name="page" value="<?=($page+1)?>"/>
                    <input type='hidden' name='user' value='<?=$user?>'>
                    <input id="submit" type="submit" class="button-next" value="Next"  id="btn1"/>
                    
                </form>
            </section>
                

            <script type="text/javascript">


            function checkform(){ 
                if(document.getElementById('q1').value==""){    
                    alert('Please input a number!');
                    document.getElementById('q1').focus();
                    return false;
                }
            }
                
                
            var progressBar = document.getElementById('pro');
              function updateProgress(newValue) {
                progressBar.value = newValue;
                  document.getElementById('num').textContent=newValue;

              }
             </script>
                
        <br></br>

        </center>
    </article>
</body>
</html> 

When I attempt to load the question page, everything about the page is displaying correctly until you pass the progress bar. After that, the live page looks like this:

    
<!DOCTYPE HTML5>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="Content-Script-Type" content="text/javascript" />
    <title>FOOD CALORIES</title>
 <link rel="stylesheet" href="css/style.css"/>
</head>

<body>
    
    <div>
        <h4><a href="index.html">Calorie4Food</a></h4>
    </div>

    <article>
        <center>
            <h5>How many calories are in the food pictured here? </h5>
            <h6>(Type a number in the box)</h6>

   <!-- progress bar -->
            <num>Progress Bar</num>
            <label2><progress id="pro" value="0" max="100"></progress></label2>
            <num id="num">0</num> <num>%</num>
            <br><br>

I'm not sure why this is be happening or where I should begin attempting to debug this problem, any advice would be greatly appreciated!

Update: /databaseAdaptor.php is there and running correctly as far as the rest of the pages are concerned. Thanks so much for catching the second require! Can't believe I missed that.

J Finder
  • 17
  • 2
  • Also your doctype is specified as HTML5. Run your code through the W3 validation. That will show an error as it should be HTML not HTML5. You also have more than one "Id" attribute. "element2" is also not allowed as a child of "center" elements. – Colin Nov 17 '17 at 18:14
  • 3
    I think it's probably not a coincidence that you're getting everything before the `require_once("/databaseAdaptor.php");`. [Do you have error reporting enabled?](https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display) – Don't Panic Nov 17 '17 at 18:17
  • @Don'tPanic HTMl and JavaScript syntax I am referring to. To me this doesn't seem like an issue with his PHP but I could be looking at this all wrong. – Colin Nov 17 '17 at 18:23
  • Actually everything seems to "break" after the br tags. So I could very possibly be the PHP. – Colin Nov 17 '17 at 18:25
  • 1
    @Colton yeah, I suspected the `require`, but really any fatal error inside the PHP block will get you half a page, and without error reporting on, no explanation for why. – Don't Panic Nov 17 '17 at 18:28
  • Actually, after a second look, I'm pretty sure that `require_once("/databaseAdaptor.php");` is a problem. Earlier in the file `require_once("./databaseAdaptor.php");` is called, so I'm guessing `/databaseAdaptor.php` doesn't exist. But really, just turn on errors and let PHP tell you for sure. – Don't Panic Nov 17 '17 at 18:33
  • @Don'tPanic Oh! Didn't even see that. Hopefully op reads this – Colin Nov 17 '17 at 18:37

0 Answers0