Okay, I’ve been through Learnable’s PHP/MySQL class with Kevin Yank twice. This is my first attempt applying my new skills to an actual site. It’s going okay so far, but my first trial to get database information to display on the page isn’t going well.
My goal is to allow the client to updates their announcements and schedule in-house. I haven’t started on the CMS portion yet, I’m just entering a couple test lines of data via PHPMyAdmin for now. When I try to get the announcement in the database to come up on the site, it’s just blank. My test line for database connection comes up, but that’s it.
Most people here could likely get this entire request done in an afternoon, but I’m coming from just doing front-end development. Please let me know what I missed in spelling or whatever so I can quit pulling my hair out. Thanks.
connect.php:
<?php
$link = mysqli_connect('localhost', 'sulluser', 'password');
if (!$link)
{
$error = 'Unable to connect to the database server.';
include 'error.php';
exit();
}
if (!mysqli_set_charset($link, 'utf8'))
{
$output = 'Unable to set database connection encoding.';
include 'error.php';
exit();
}
if (!mysqli_select_db($link, 'sullSite12'))
{
$error = 'Unable to locate the joke database.';
include 'error.php';
exit();
}
$output = 'Yes, it is connected.';
include 'index.php';
?>
magicquotes.php:
<?php
if (get_magic_quotes_gpc())
{
function stripslashes_deep($value)
{
$value = is_array($value) ?
array_map('stripslashes_deep', $value) :
stripslashes($value);
return $value;
}
$_POST = array_map('stripslashes_deep', $_POST);
$_GET = array_map('stripslashes_deep', $_GET);
$_COOKIE = array_map('stripslashes_deep', $_COOKIE);
$_REQUEST = array_map('stripslashes_deep', $_REQUEST);
}
?>
helpers.php:
<?php
function html($text)
{
return htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
}
function htmlout($text)
{
echo html($text);
}
?>
announce.php:
<?php
include 'assets/includes/connect.php';
include 'assets/includes/magicquotes.php';
//Read the announcements
$sql = 'SELECT id, eventday, event FROM announcement';
$eventitem = mysqli_query($link, $sql);
//If something went wrong
if(!$eventitem)
{
$error = 'Could not get announcement information.';
include 'index.php';
exit();
}
//Get information and store it in variable announcements
while ($row = mysqli_fetch_array($eventitem))
{
$announcements[] = array('id' => $row['id'], 'date' => $row['eventday'], 'text' => $row['event']);
}
include 'index.php';
exit();
?>
index.php (go about 3/4 down for relevant sections):
<?php include_once 'assets/includes/connect.php'; ?>
<?php include 'assets/includes/helpers.php'; ?>
<!doctype html>
<html lang="en"><!-- InstanceBegin template="/Templates/mainp.dwt.php" codeOutsideHTMLIsLocked="false" -->
<head>
<meta charset="utf-8">
<!-- InstanceBeginEditable name="doctitle" -->
<title>Sully Christian Grade</title>
<!-- InstanceEndEditable -->
<script src="assets/js/jquery-1.5.min.js"></script>
<!-- InstanceBeginEditable name="head" -->
<script type="text/javascript" src="http://malsup.github.com/chili-1.7.pack.js"></script>
<script type="text/javascript" src="http://malsup.github.com/jquery.cycle.all.js"></script>
<script type="text/javascript">
$('#picslideshow').cycle({
fx: 'fade',
speed: 900,
timeout: 4000,
pause: 1,
random: 1
});
</script>
<meta name="google-site-verification" content="m6fPzAV80csLHBOv4R7AVDtD1MgrQLZkSL3Crjn_CO4" />
<meta name="description" content="Sully Christian Grade School is located in south central Iowa. Our students receive Christ-centered education with a student teacher ratio of 8:1.">
<!-- InstanceEndEditable -->
<link href="assets/scs20.css" rel="stylesheet" type="text/css">
<script src="SpryAssets/SpryMenuBar.js" type="text/javascript"></script>
<!--[if lt IE 8]>
<link href="http://www.sullychristian.org/assets/oldie.css" rel="stylesheet" type="text/css">
<![endif]-->
<link href="SpryAssets/SpryMenuBarHorizontal.css" rel="stylesheet" type="text/css">
</head>
<body>
<div id="masterpage">
<div id="header">
<img src="assets/images/site/banner-150.jpg" alt="Sully Christian Grade School" width="1024" height="150">
</div>
<div class="navBlack"></div>
<div id="nav">
<ul id="MenuBar1" class="MenuBarHorizontal">
<li id="home"><a href="index.php" class="navborder" title="Home">Home</a></li>
<li id="about"><a href="#" title="About" class="MenuBarItemSubmenu navborder">About</a>
<ul>
<li><a href="about/mission.php" title="Mission Statement">Mission Statement</a></li>
<li><a href="about/quickfacts.php" title="Quick Facts">Quick Facts</a></li>
<li><a href="about/faculty.php" title="Faculty">Faculty</a></li>
<li><a href="about/board.php" title="Board">Board</a></li>
<li><a href="about/committees.php" title="Committees">Committees</a></li>
<li><a href="about/history.php" title="History">History</a></li>
</ul>
</li>
<li id="academics"><a href="#" class="MenuBarItemSubmenu navborder">Academics</a>
<ul>
<li><a href="academics/classrooms.php" title="Classrooms">Classroooms</a></li>
<li><a href="academics/itbs.php" title="ITBS Scores">ITBS Scores</a></li>
<li><a href="academics/iacore.php" title="Iowa Core">Iowa Core</a></li>
</ul>
</li>
<li id="calendars"><a class="MenuBarItemSubmenu navborder" href="#">Calendars</a>
<ul>
<li><a href="calendar.php" title="Main Calendar">Main Calendar</a></li>
<li><a href="assets/pdf/calendars/academiccalendar.pdf" title="Academic Calendar" class="external">Academic</a></li>
<li><a href="assets/pdf/calendars/schoolcalendar.pdf" title="School Calendar" class="external">School</a></li>
<li><a href="assets/pdf/calendars/lunch.pdf" title="Lunch" class="external">Lunch</a></li>
<li><a href="assets/pdf/calendars/sportsschedule.pdf" title="Athletic" class="external">Athletic</a></li>
</ul>
</li>
<li id="news"><a href="#" class="MenuBarItemSubmenu navborder">News</a>
<ul>
<li><a href="assets/pdf/newsletter/scsnewsletter/scsnewsletter.pdf" title="SCS Newsletter" class="external">SCS Newsletter</a></li>
<li><a href="assets/pdf/newsletter/bitspieces/bitspieces.pdf" title="Bits 'n Pieces" class="external">Bits 'n Pieces</a></li>
<li><a href="newsletter.php" title="News">Newsletter Archives</a></li>
</ul>
</li>
<li id="athletics"><a href="#" title="Warrior Athletics" class="MenuBarItemSubmenu navborder">Warrior Athletics</a>
<ul>
<li><a href="athletics/athletics.php" title="Warrior Athletics">Athletics</a></li>
<li><a href="assets/pdf/forms/physicalform.pdf" title="Physical Form" class="external">Physical Form</a></li>
<li><a href="assets/pdf/calendars/sportsschedule.pdf" title="Schedule" class="external">Schedule</a></li>
<li><a href="athletics/scores.php" title="Scores">Scores</a></li>
<li><a href="athletics/directions.php" title="Directions">Directions</a></li>
</ul>
</li>
<li id="parents"><a href="#" class="MenuBarItemSubmenu navborder">Parents</a>
<ul>
<li><a href="assets/pdf/newsevents/parenthandbook.pdf" title="Parent Handbook" class="external">Parent Handbook</a></li>
<li><a href="assets/pdf/newsevents/supplylist.pdf" title="School Supply List" class="external">School Supply List</a></li>
<li><a href="parents/trip.php" title="TRIP">TRIP</a></li>
<li><a href="parents/tuitionhelp.php" title="Tuition Assistance">Tuition Assistance</a></li>
<li><a href="https://rodlanapps.com/cgi-bin/WAV/acntview.cgi#ec1ARgw69U54eHh4" title="Lunch Account" class="external">Lunch Account</a></li>
<li><a href="assets/pdf/ReducedLunchApplication.pdf" title="Free or Reduced Lunch Application" class="external">Free & Reduced Lunch Application</a></li>
<li><a href="https://schoolalerts.iowa.gov/10194-School_Alerts/index.jsp" title="School Alerts" class="external">School Alerts</a></li>
</ul>
</li>
<li id="donate"><a href="#" class="MenuBarItemSubmenu navborder">Donate</a>
<ul>
<li><a href="donate/logsto.php" title="LOG/STO">LOG/STO</a></li>
<li><a href="donate/scholarships.php" title="Scholarships">Scholarships</a></li>
<li><a href="donate/endowment.php" title="Endowment">Endowment</a></li>
<li><a href="donate/support.php" title="Matching Gift Employers">Matching Gift Employers</a></li>
</ul>
</li>
<li id="fundraising"><a href="fundraising.php" title="Fundraising" class="navborder">Fundraising</a></li>
<li id="links"><a href="links.php" title="Links" class="navborder">Links</a></li>
<li id="contact"><a href="#" title="Contact" class="navborderend">Contact</a>
<ul>
<li><a href="contact/contact.php" title="School Contact">School</a></li>
<li><a href="http://maps.google.com/maps?q=12629+S+92nd+Ave+E,+Sully,+IA&hl=en&sll=37.0625,-95.677068&sspn=41.767874,71.455078&z=16" title="School Map" class="external">Find Us</a></li>
<li><a href="contact/staffdirectory.php" title="School Directory">School Directory</a></li>
<li><a href="contact/employment.php" title="Employment">Employment</a></li>
</ul>
</li>
</ul>
</div>
<div class="navBlack"></div>
<div id="main">
<div id="maincontent">
<div id="pageContent">
<!-- InstanceBeginEditable name="Content" -->
<div id="picslideshow">
<img src="assets/images/index/index01.jpg" alt="Sully Christian School" width="540" height="270" class="start">
<img src="assets/images/index/index02.jpg" alt="School Entrance" width="540" height="270">
<img src="assets/images/index/index03.jpg" alt="School Entrance" width="540" height="270">
<img src="assets/images/index/index04.jpg" alt="School Hall" width="540" height="270">
<img src="assets/images/index/index05.jpg" alt="Classroom" width="540" height="270">
<img src="assets/images/index/index06.jpg" alt="Computer Lab" width="540" height="270">
<img src="assets/images/index/index07.jpg" alt="High Jump" width="540" height="270">
<img src="assets/images/index/index08.jpg" alt="Two Boys" width="540" height="270">
<img src="assets/images/index/index09.jpg" alt="Basketball Court" width="540" height="270">
<img src="assets/images/index/index10.jpg" alt="Playground" width="540" height="270">
</div> <!-- End slideshow -->
<div id="greeting">
<p>Welcome to Sully Christian School! Our school is a place where God's Word serves as the foundation to empower students to follow the Master Teacher, Jesus Christ, and enables our teachers to fulfill our school's commitment to help nurture students in excellence and truth for their Creator.</p>
<p>Students are encouraged and challenged to work to their full potential as they develop their God-given talents to serve as God's disciples in His Kingdom.</p>
<p>Thanks for visiting our website. Stay a while and explore to learn more about our school.<br>
<span class="rightalign">-Karen Hackert, Head Teacher</span></p>
</div>
<div id="theme"> <img src="assets/images/theme.jpg" width="145" height="75" alt="Power Up!">This year's theme, "Power Up," is centered around Philippians 4:13 <span class="italics">"I can do all things through Christ who strengthens me."</span><br>
Our song for 2011-12 is: <a href="http://youtu.be/rPR3zj0PtKM" title="Faith by Hillsong" class="external"><span class="italics">Faith</span> by Hillsong</a> </div>
<div id="indexnews">
<h2>Announcements</h2>
<?php echo $error; ?>
<?php foreach ($announcements as $event): ?>
<p>
<?php htmlout($announcement['date']); ?>
<?php htmlout($event['text']); ?>
</p>
<?php endforeach; ?>
<?php echo $output; ?>
</div>
<!-- InstanceEndEditable -->
</div> <!-- end pagecontent -->
<div id="rightside">
<div id="infoBox">
<h3>Quick Links</h3>
<ul class="quicklink">
<li><a href="index.php" title="Home">Home</a></li>
<li><a href="calendar.php" title="School Calendar">School Calendar</a></li>
<li><a href="https://rodlanapps.com/cgi-bin/WAV/acntview.cgi#ec1ARgw69U54eHh4" title="School Lunch Account" class="external">School Lunch Account</a></li>
<li><a href="parents/trip.php" title="TRIP">TRIP</a></li>
<li><a href="newsletter.php" title="Newsletters">Newsletters</a></li>
<li><a href="http://www.schoolnet8.com/site.phtml?station=SSUI4&station2=SCSI4" title="Weather Station" class="external">Weather Station</a></li>
<li><a href="https://schoolalerts.iowa.gov/10194-School_Alerts/index.jsp" title="School Alerts" class="external">School Alerts</a></li>
<li><a href="https://picasaweb.google.com/sullychristian05" title="Recent Event Pictures" class="external">Recent Event Pictures</a></li>
</ul>
<h3>Upcoming Events</h3>
<ul>
<li>March 23: 1:30 Dismissal -End of 3rd Quarter</li>
<li>March 28: 2:30 Dismissal -Parent Teacher Conferences</li>
<li>March 29: Parent Teacher Conferences PM</li>
<li>March 30: No School</li>
<li>April 5: No School -In-service</li>
<li>April 6: No School -Good Friday</li>
</ul>
<h3>Contact Information</h3>
<p>12629 S 92nd Ave E<br />
Sully, IA 50251</p>
<p>Phone: 641-594-4180<br>
Fax: 641-594-3799
</p>
<p>Email: <a href="mailto:lloftus@sullychristian.org" title="Mail Sully Christian">lloftus@sullychristian.org</a></p>
<div id="cse-search-form" style="width: 100%;">Loading</div>
<script src="http://www.google.com/jsapi" type="text/javascript"></script>
<script type="text/javascript">
google.load('search', '1', {language : 'en'});
google.setOnLoadCallback(function() {
var customSearchControl = new google.search.CustomSearchControl('008298257734023449732:eesga3goiha');
customSearchControl.setResultSetSize(google.search.Search.FILTERED_CSE_RESULTSET);
var options = new google.search.DrawOptions();
options.enableSearchboxOnly("http://www.google.com/cse?cx=008298257734023449732:eesga3goiha", null, true);
customSearchControl.draw('cse-search-form', options);
}, true);
</script>
<link rel="stylesheet" href="http://www.google.com/cse/style/look/default.css" type="text/css" />
<style type="text/css">
input.gsc-input {
border-color: #a52a2a;
}
input.gsc-search-button {
border-color: #666666;
background-color: #CECECE;
}
</style>
</div> <!-- End infobox -->
</div> <!-- End rightside -->
</div> <!-- End maincontent -->
</div> <!-- End main -->
<div id="footer">Sully Christian Grade School | 12629 S 92nd Ave E | Sully, IA 50251 | 641-594-4180</div>
</div> <!-- End masterpage -->
<script src="assets/js/links.js"></script>
<script type="text/javascript">
var MenuBar1 = new Spry.Widget.MenuBar("MenuBar1", {imgDown:"", imgRight:""});
</script>
<!--<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-1841699-24']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>-->
</body>
<!-- InstanceEnd --></html>