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.