...

View Full Version : PHP Anomaly



jchrisphonte
01-23-2012, 04:57 PM
Hello -
I am using the below code on hedgevent.com/reviews.php --- any idea why
it is not posting the php query and sidebar images??




<head>
<meta charset="utf-8" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="stylereviews.css" rel="stylesheet" type="text/css" />
<title>Hedge Fund Events</title>
<style type="text/css">
body{background-image:url('background.png');}
</style>

<script type="text/javascript" src="js/search.js"></script>
<script type="text/javascript" src="js/pagination.js"></script>
<script> htmlData('search.php', ''); </script>
<style type="text/css">
#sidebar img {
margin-bottom:10px;
}
</style>
<script type="text/javascript">

var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-28203080-1']);
_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>
</head>

<body>
<div class=wrapper>
<section id="bar">
<div class="header">
<div class="banner">
</div>
</div>
<div class="navbar">
<ul class="firstbar">
<li><a href="index.php">Hedge Fund Events</a>
</li>
<li><a href="calendar.php">Events Calendar</a>
</li>
<li><a href="reviews.php">Submit Reviews</a>
</li>
<li><a href="addevents.html">Add Events</a>
</li>
<li><a href="directory.php">HF Vendors</a>
</li>
</ul>
<ul class="secondbar">
<li><a href="contact.html">Contact</a></li>
<li><a href="adratetest.pdf">Advertise</a></li>
</ul>
</div>
</section>
<div id="container">
<div id="listing">

<!-- begin content -->
<div id="content">
<!-- begin form -->
<div id="form">
<input type="text" id="terms" size="40" onkeyup="getScriptPage('show_results','terms','1')" onblur="if ( this.value == '' ) this.value = this.defaultValue" onfocus="if ( this.value == this.defaultValue ) this.value = ''" value="type your search here" /></div><!-- end form -->
</div><!-- end content -->
<span class='add'><a href='addevents.php' title='Add Event'>Add Event</a></span>
<!-- begin counter display -->
<div id="show_results"></div><!-- end counter display -->

<div id="php">
<br><br>

<?php if (!isset($_SESSION)) session_start();

include('check.php');
include('dbconn.php');

if(isset($_SESSION['username'])):

$day = date('d');
$month = date('m');
$year = date('Y');

echo "<div id='upcoming'>";
echo "<h3>Recently Past Events ".date('F', mktime(0,0,0,$month,1))." '".date('y')."</h3><br>";

$sql = "SELECT * FROM calendar_event WHERE day >= '$day' AND month = '$month' AND year = '$year' LIMIT 0,10";
$result = mysql_query($sql);

$count = mysql_num_rows($result);

if($count == 0) echo "<span class='error_message'>There are no past events last month.</span>";

echo "<ul class='upcoming-events'>";

while($row = mysql_fetch_array($result)):

echo "<li><a href='cal_edit.php?evid=".$row['id']."'>".$row['event'];
echo "&nbsp;-&nbsp;<span class='upcoming-date'>".$row['day']."/".$row['month']."/".$row['year']."</span></a></li>";

endwhile;

echo "</ul>";

echo "</div>";

endif;
?>
</div>

</div>
<div id="vrule"> <img src="vrline.png" HEIGHT="600" width="12">
</div>
<div id="sidebar"> <img src="geneva.gif" HEIGHT="160" width="160"> <img src="emirates.gif" HEIGHT="600" width="160">
</div>

</div>


</div>
</body>

</html>

BluePanther
01-23-2012, 05:54 PM
if (!isset($_SESSION)) session_start(); should be at the very start of your document. You don't need the if condition either, since it will always evaluate true. Also, you're not doing any error reporting on your query - add an 'or die()' or check for a false $result.

It looks like your logic isn't correct either. If it's events in the past month, surely day should be <= to today?

tangoforce
01-23-2012, 06:39 PM
As BP says, you should always call session_start(). Checking for $_SESSION is pointless because any script that uses sessions MUST have a call to session_start() irrespective of whether this script started/created the session.

session_start() doesn't just start a session (this is a problem with the name that gives the impression it does) but it also reopens/resumes a session that was created by another script. Therefore you must always use this function call in ANY script that uses sessions.

jchrisphonte
01-23-2012, 06:41 PM
Hi BluePanther,

Thank you for your help ...

I am new to PHP and I used php code I found in another part of my site (shows upcoming events) and hoped to tweak it to show events from the last 30 days instead...


i cant find this in my code "if(isset($_POST['submitButton']))"
please do let me know if i have missed something.

and about listing the "if (!isset($_SESSION)) session_start();" at the beginning - do you mean in the head tags or after first body tag??
trying to get it to appear like : hedgevent.com homepage.

I am very appreciative for your help.

Jerry

jchrisphonte
01-23-2012, 06:50 PM
I agree with your logic BluePanther,

I've since changed the day to <=.... How can I get this query to show events of the past 60 days?? not including today's events?


$sql = "SELECT * FROM calendar_event WHERE day <= '$day' AND month = '$month' AND year = '$year' LIMIT 0,10";

BluePanther
01-23-2012, 07:11 PM
We mean right at the top of the document, before head or even doctype. The very first bit of the file.

PHP is executed server side, html is sent to the client after all the server side stuff has been done. PHP can output html, but html has no influence over PHP.

tangoforce
01-23-2012, 07:23 PM
Hi BluePanther,

i cant find this in my code "if(isset($_POST['submitButton']))"
please do let me know if i have missed something.


Jerry,

Thats part of BluePanthers SIGNATURE. It's an advisory tip for new programmers (based on my signature which is similar below -the original and best :D). He wasn't intentionally saying you had it in your code.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum