Kay1021 Posted June 27, 2009 Share Posted June 27, 2009 I'm wondering if someone might look over my code and see what i might have done wrong 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 //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'); $currMonth= date('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écembre">Décembre</option> <option value="Janvier">Janvier</option> <option value="Février">Fé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 ?> Link to comment https://forums.phpfreaks.com/topic/163906-problem-with-code-cant-find-fix-myself/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.