TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 06-28-2009, 07:00 PM   #1 (permalink)
The Contributor
 
Join Date: May 2008
Posts: 36
Thanks: 5
Kay1021 is on a distinguished road
Default Cannot find the problem

I'm wondering if someone might look over my code and see what i might have done wrong.

I've spent so much time trying to tear this apart...rebuild...move thing around change things I cannot figure this out... I was hoping for some fresh eyes.

I'm trying to have three different select boxes along the top that allow you to choose a school, the month and the year. Then a table is outputted from those results with some javscript that when you check the checkbox, or choose a date, or add a comment that it's automatically added to the database.

I've used this code and when I take out the whole choosing a school and it's just present for one school ...removing the $school =$_POST['school']; and such it works perfectly...but i need to be able to change schools

Everytime you refresh the page the $school seems to be empty so it reverts to the default and doesn't save anything. I've tried everything i can think of and nothing will make the school not empty when you fresh....choosing schools from the drop down it does show the right schools and everything though


Hopefully someone can help...thanks

PHP Code:
<?php
   
                
//connect to database
                
                
                
                
      
$school =$_POST['school'];
      
                
//determine current school if empty
      
if(empty($school)){
         
$school='school';
      }
      
      
$yr $_POST['yr'];
      
      
//determine current yr if empty
      
if (empty($yr)) {
         
$currYr date('Y');
         
$currMonthdate('m');
         
         if (
$currMonth<=09 && $currMonth>=12){
            
$currYr2=date('Y')+1;
            
$yr=  $currYr."_"$currYr2;
            
         } else {
            
$currYr2=date('Y')-1;
            
$yr=  $currYr2."_"$currYr;
         }
      }
      
                
//change yr for looks      
      
$year preg_replace('/_/'' - '$yr);
                
      
      
//Set date language to french and determine month
      
setlocale (LC_TIME'fr_FR');
           
      
$month $_POST['month'];

                
//determine current month if empty
      
if(empty($month)){
         
$month strftime ("%B");
         
$month ucwords($month);
      }
      
      
      
//creates table name 
      
$tableName $school.$yr;
      
      
      
//Updates database with content from editable textarea
      
if(is_numeric($_GET['id']) && isset($_GET['comment']))
      {
         
$query "UPDATE $tableName SET comment = '".mysql_real_escape_string(stripslashes($_GET['comment']))."' WHERE cat_id = ".(int)$_GET['id'];
   
         
$result mysql_query($query,$db_link) or  die('Error: ' mysql_error());

      }
      
                
//Updates database with content from checkbox
      
if(isset($_GET['chkmark']) && isset($_GET['catID']))
      {
      
         
$chkmark $_GET['chkmark'];
         
$catID $_GET['catID'];
      
         if (
$chkmark == 'false'){
         
            
$chkmark='on';
         } else {
         
            
$chkmark='off';
         }
         
$query2 "UPDATE $tableName SET confirm = '".$chkmark."' WHERE cat_id = ".$catID."";
   
         
$result2 mysql_query($query2,$db_link) or  die('Error: ' mysql_error());

      }
      
                
                
//Updates database with content from datepicker
      
if(isset($_GET['date']) && isset($_GET['cat_ID']))
      {
      
         
$date $_GET['date'];
         
$catID $_GET['cat_ID'];
      
         
$query2 "UPDATE $tableName SET date = '".$date."' WHERE cat_id = ".$catID."";
   
         
$result2 mysql_query($query2,$db_link) or  die('Error: ' mysql_error());

      }
      
      
      
      
   
   
/*--------------------------------------START MENU------------------------------------------------*/           
   
echo '
      <div id="centeredmenu">
         <ul>
                  
           <li class="selectBox">
                 <a>
                  <form method="POST" action="schoolPageAdmin.php" name="form_sch">
                        <select name="school" value="Choose School" OnChange ="document.form_school.submit();">
                           <option value="'
.$school.'">'.$school.'</option>
                           <option value="'
.$schoo2.'">'.$schoo2.'</option>
                                                                        <option value="'
.$schoo3.'">'.$schoo3.'</option>
                                                                        <option value="'
.$schoo4.'">'.$school4.'</option>
                                                                        <option value="'
.$school5.'">'.$school5.'</option>
                        </select>
                        
                        <input type="hidden" name="school" value='
.$month.'>
                        <input type="hidden" name="yr" value='
.$yr.'>
                        
                     </form>
                     
               </a>
               
           </li>'
;
           
$school=$_POST['school'];
           echo
'
            <li class="selectBox">
                 <a>
                     <form method="POST" action="schoolPageAdmin.php" name="form_mth">
                        <select name="month" value="Choose Month" OnChange ="document.form_mth.submit();">
                           <option value="'
.$month.'">'.$month.'</option>
                           <option value="Septembre">Septembre</option>
                           <option value="Octobre">Octobre</option>
                           <option value="Novembre">Novembre</option>
                           <option value="D&#233;cembre">D&#233;cembre</option>
                           <option value="Janvier">Janvier</option>
                           <option value="F&#233;vrier">F&#233;vrier</option>
                           <option value="Mars">Mars</option>
                           <option value="Avril">Avril</option>
                           <option value="Mai">Mai</option>
                           <option value="Juin">Juin</option>
                        </select>
                        
                        <input type="hidden" name="school" value='
.$school.'>
                        <input type="hidden" name="yr" value='
.$yr.'>
                        
                     </form>
                  </a>
               
           </li>
          <li class="selectBox">
                 <a>
                  <form method="POST" action="schoolPageAdmin.php" name="form_yr">'
;
                     
//--SELECT CATEGORIES FOR DROP DOWN
                     
$query3="SELECT year FROM years";
                                    
                     
$result3 mysql_query ($query3);
                                    
                     echo
'<select name="yr" value="Choose Year" OnChange ="document.form_yr.submit();">
                                       
                        '
;                                 
                        echo 
"<option value='$yr'>$yr</option>";
                                                       
                           while(
$nt3=mysql_fetch_array($result3))
                           {
                              
$yr$nt3['year'];
                                                
                              echo 
'<option value="'.$nt3[year].'">'.$yr.'</option>';
                           
                           }
                           
                     echo
'</select>
                     
                     <input type="hidden" name="month" value='
.$month.'>
                     <input type="hidden" name="school" value='
.$school.'>
                     
                        
                  </form>
               </a>
               
           </li>'
;

           echo
'
           
         </ul>
      </div>'
;

//TABLE OUTPUTS
?>
Kay1021 is offline  
Reply With Quote
Old 06-28-2009, 07:08 PM   #2 (permalink)
La Vida es Sueño
Advanced Programmer Top Contributor 
 
Wildhoney's Avatar
 
Join Date: Sep 2007
Location: Oldham
Posts: 2,280
Thanks: 90
Wildhoney is on a distinguished road
Default

It would be better to store the data from the school in a session, and then when the page is reloaded it will be remembered. If the session is empty then you'd return to the default. However, if they wanted to change the school then you'd simply update the session variable and continue.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
Send a message via AIM to Wildhoney Send a message via MSN to Wildhoney Send a message via Yahoo to Wildhoney
Wildhoney is offline  
Reply With Quote
Old 06-28-2009, 07:13 PM   #3 (permalink)
The Contributor
 
Join Date: May 2008
Posts: 36
Thanks: 5
Kay1021 is on a distinguished road
Default

I'm kinda new to sessions...but can you use more than one session...i have a session going already for a log in thing
Kay1021 is offline  
Reply With Quote
Old 06-29-2009, 09:17 AM   #4 (permalink)
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Well technically you can only have one session per ... well ... session, however a session in PHP is essentially an array so you can have multiple values (session variables):
PHP Code:
$_SESSION['login_thing'] = true;
$_SESSION['something_else'] = 'turtles'
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote
The Following User Says Thank You to sketchMedia For This Useful Post:
Kay1021 (06-29-2009)
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Huge Session Problem Killswitch General 1 11-17-2008 02:36 AM
A bug or a cache problem?! yazid Advanced PHP Programming 0 05-22-2008 08:40 AM
Keep getting mySQL error No. 1064, but i can't seem to find the problem Durux MySQL & Databases 8 04-13-2008 07:51 PM
get_included_files to find originating script? solistus General 4 04-08-2008 10:16 PM
Hi everyone. I am so excited to find this site again..!! hellenmoranov The Lounge 1 04-01-2007 10:59 PM


All times are GMT. The time now is 01:09 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design