chessmith Posted July 16, 2007 Share Posted July 16, 2007 Hi, I'm new here and very new to PHP and MySQL. I work at a Middle School and am developing an employee portal for our faculty to access. I am trying to create a computer lab sign up that will list all the dates and periods available and will give them the option of selecting their userid from a drop down menu in order to reserve the lab for that period. We have alot of tech unsavy people so it has to be very simple. All I want in the drop down is the word 'Available' and their User ID (which will reserve the lab). Once the lab is reserved all I want is for their user id to be displayed instead of the drop down menu in order to indicate the reservation. Below is the code and it works exactley like I want it to only it doesn't update the database. Any help would be greatly appreciated. <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $currentPage = $_SERVER["PHP_SELF"]; $editFormAction = $_SERVER['PHP_SELF']; if (isset($_SERVER['QUERY_STRING'])) { $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); } if((isset($_POST["MM_update"])) && ($_POST["MM_update"] == "form2")) { $updateSQL = sprintf("UPDATE lab103 SET AMTutorial=%s, oneFive=%s, SPARK=%s, twoSix=%s, threeSeven=%s, fourEight=%s, PMTutorial=%s WHERE `lab_id`=%s", GetSQLValueString($_POST['AMTutorial'], "text"), GetSQLValueString($_POST['oneFive'], "text"), GetSQLValueString($_POST['SPARK'], "text"), GetSQLValueString($_POST['twoSix'], "text"), GetSQLValueString($_POST['threeSeven'], "text"), GetSQLValueString($_POST['fourEight'], "text"), GetSQLValueString($_POST['PMTutorial'], "text"), GetSQLValueString($_POST['lab_id'], "int")); mysql_select_db($database_JMS_Portal, $JMS_Portal); $Result1 = mysql_query($updateSQL, $JMS_Portal) or die(mysql_error()); $updateGoTo = "lab103.php"; if (isset($_SERVER['QUERY_STRING'])) { $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?"; $updateGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $updateGoTo)); } $maxRows_lab103 = 20; $pageNum_lab103 = 0; if (isset($_GET['pageNum_lab103'])) { $pageNum_lab103 = $_GET['pageNum_lab103']; } $startRow_lab103 = $pageNum_lab103 * $maxRows_lab103; mysql_select_db($database_JMS_Portal, $JMS_Portal); $query_lab103 = "SELECT * FROM lab103"; $query_limit_lab103 = sprintf("%s LIMIT %d, %d", $query_lab103, $startRow_lab103, $maxRows_lab103); $lab103 = mysql_query($query_limit_lab103, $JMS_Portal) or die(mysql_error()); $row_lab103 = mysql_fetch_assoc($lab103); if (isset($_GET['totalRows_lab103'])) { $totalRows_lab103 = $_GET['totalRows_lab103']; } else { $all_lab103 = mysql_query($query_lab103); $totalRows_lab103 = mysql_num_rows($all_lab103); } $totalPages_lab103 = ceil($totalRows_lab103/$maxRows_lab103)-1; $queryString_lab103 = ""; if (!empty($_SERVER['QUERY_STRING'])) { $params = explode("&", $_SERVER['QUERY_STRING']); $newParams = array(); foreach ($params as $param) { if (stristr($param, "pageNum_lab103") == false && stristr($param, "totalRows_lab103") == false) { array_push($newParams, $param); } } if (count($newParams) != 0) { $queryString_lab103 = "&" . htmlentities(implode("&", $newParams)); } } $queryString_lab103 = sprintf("&totalRows_lab103=%d%s", $totalRows_lab103, $queryString_lab103); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> <style type="text/css"> <!-- .style2 {font-size: large} --> </style> </head> <body> <form action="<?php echo $editFormAction; ?>" method="POST" name="form2" target="_self"> <table width="1024" border="2"> <tr> <th scope="col"><span class="style2">Date:</span></th> <th scope="col"><span class="style2">AM Tutorial:</span></th> <th scope="col"><span class="style2">1st/5th</span></th> <th scope="col"><span class="style2">SPARK</span></th> <th scope="col"><span class="style2">2nd/6th</span></th> <th scope="col"><span class="style2">3rd/7th</span></th> <th scope="col"><span class="style2">4th/8th</span></th> <th scope="col"><span class="style2">PM Tutorial </span></th> </tr> <?php do { ?> <tr> <td><?php if($row_lab103['Day']=="Purple Day") { echo "<font color=purple>$row_lab103[Date]"; } elseif($row_lab103['Day']=="Purple Day (ED)") { echo "<bg color=purple>$row_lab103[Date] (ED)"; } elseif($row_lab103['Day']=="Gray Day"){ echo "<font color=gray>$row_lab103[Date]"; } elseif($row_lab103['Day']=="Gray Day (ED)") { echo "<font color=gray>$row_lab103[Date] (ED)"; } ?></td> <td><div align="center"> <?php if($row_lab103['AMTutorial'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='AMTutorial' size='1' id='AMTutorial'><option value=''>$row_lab103[AMTutorial]</option><option value='$user'>$user</option></select>"; } else { echo "$row_lab103[AMTutorial]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['oneFive'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='oneFive' size='1' id='oneFive'><option value=''>$row_lab103[oneFive]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[oneFive]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['SPARK'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='SPARK' size='1' id='SPARK'><option value=''>$row_lab103[sPARK]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[sPARK]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['twoSix'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='twoSix' size='1' id='twoSix'><option value=''>$row_lab103[twoSix]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[twoSix]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['threeSeven'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='threeSeven' size='1' id='threeSeven'><option value=''>$row_lab103[threeSeven]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[threeSeven]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['fourEight'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='fourEight' size='1' id='fourEight'><option value=''>$row_lab103[fourEight]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[fourEight]"; } ?> </div></td> <td><div align="center"> <?php if($row_lab103['PMTutorial'] == 'Available'){ $user = ($_SESSION['MM_Username']); echo "<select name='PMTutorial' size='1' id='PMTutorial'><option value=''>$row_lab103[PMTutorial]</option><option value='$_SESSION[MM_Username]'>$_SESSION[MM_Username]</option></select>"; } else { echo "$row_lab103[PMTutorial]"; } ?> </div></td> </tr> <?php } while ($row_lab103 = mysql_fetch_assoc($lab103)); ?> </table> <p> <input name="submit" type="submit" value="Submit"> <input type="hidden" name="MM_update" value="form2"> <input type="hidden" name="lab_id" value="<?php echo $row_lab103['lab_id']; ?>"/> </p> <table border="0" width="50%" align="left"> <tr> <td width="23%" align="center"><?php if ($pageNum_lab103 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_lab103=%d%s", $currentPage, 0, $queryString_lab103); ?>">First</a> <?php } // Show if not first page ?> </td> <td width="31%" align="center"><?php if ($pageNum_lab103 > 0) { // Show if not first page ?> <a href="<?php printf("%s?pageNum_lab103=%d%s", $currentPage, max(0, $pageNum_lab103 - 1), $queryString_lab103); ?>">Previous</a> <?php } // Show if not first page ?> </td> <td width="23%" align="center"><?php if ($pageNum_lab103 < $totalPages_lab103) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_lab103=%d%s", $currentPage, min($totalPages_lab103, $pageNum_lab103 + 1), $queryString_lab103); ?>">Next</a> <?php } // Show if not last page ?> </td> <td width="23%" align="center"><?php if ($pageNum_lab103 < $totalPages_lab103) { // Show if not last page ?> <a href="<?php printf("%s?pageNum_lab103=%d%s", $currentPage, $totalPages_lab103, $queryString_lab103); ?>">Last</a> <?php } // Show if not last page ?> </td> </tr> </table> </p> </form> <p> </p> </body> </html> <?php mysql_free_result($lab103); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.