Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 7 of 7

Thread: PHP Anomaly

  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts

    PHP Anomaly

    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??


    Code:
     
    <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>

  • #2
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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?
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (01-23-2012)

  • #3
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    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.
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    jchrisphonte (01-23-2012)

  • #4
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    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

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    84
    Thanks
    49
    Thanked 0 Times in 0 Posts
    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?

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

  • #6
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    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.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • Users who have thanked BluePanther for this post:

    jchrisphonte (01-23-2012)

  • #7
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    Quote Originally Posted by jchrisphonte View Post
    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 ). He wasn't intentionally saying you had it in your code.
    I can't really think of anything to write here now...

  • Users who have thanked tangoforce for this post:

    jchrisphonte (01-23-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •