Jump to content

cougar23

Members
  • Posts

    30
  • Joined

  • Last visited

    Never

Everything posted by cougar23

  1. It looks like that worked I think. Thanks to all
  2. in a definitions.inc file that I include at the top of the page. Right now debugging, the page looks like this: <!-- import common php servier-side functions library --> <?php require_once('../includes/common_fns.inc'); ?> <!-- import directory defintions file --> <?php require_once('definitions.inc'); ?> <!-- DIV TO SHOW STATUS MESSAGE, IF REQUIRED AFTER PAGE RENDERS --> <div id="statusMsgDiv"> <label id="statusMsgOutput"></label> </div> <?php //show status message if necessary after page has rendered; HARD-CODED TEST FOR NOW $_SESSION['statusMsg'] = 'LATE_NEXT_DAY_ERROR'; displayStatusMessageIfRequired($studentErrorMessages, null); ?> and then the function code in common_fns.inc is: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; }
  3. I have an array of error messages with keys defined, and I want to output the message associated with a key to the screen, but my code is outputting the key. My array is like this: $studentErrorMessages = array( 'LATE_NEXT_DAY_ERROR' => 'You can not reserve an appointment for the following day after 3:00 PM. Please select another appointment', 'APPT_NOW_RESERVED_ERROR' => 'The requested appointment is no longer available. Please select a different appointment', 'CANCEL_NOT_ALLOWED' => 'You can not cancel your appointment after 3:00 PM the day before your appointment. Please email your advisor if you are unable to attend your scheduled appointment' ); And then my code to output the error message is this: //if key was found in the error messages array, echo javascript to show the message in RED error message color if(array_key_exists($messageKey, $errorMsgDefinitionsArray)){ echo '<script type="text/javascript">'; echo ' document.getElementById("statusMsgDiv").style.display = "block"; '; echo ' document.getElementById("statusMsgOutput").classname = "red bold"; '; echo ' document.getElementById("statusMsgOutput").value = "'.$errorMsgDefinitionsArray[$messageKey].'"; '; echo '</script>'; } So testing, I have set the $messageKey = 'LATE_NEXT_DAY_ERROR' and instead of displaying the error description, it's displaying 'LATE_NEXT_DAY_ERROR' . What am I doing wrong? Thanks for the help ahead of time.
  4. In and calendar/scheduling UI, I have two JS arrays (originalTimeSlots & currentTimeSlots) that store boolean values on if the checkbox for that time slot is selected or not. They are both associative arrays with the index/key being in the format "DATE;APPT_START_TIME;APPT_END_TIME", i.e. originalTimeSlots["2008-11-17;08:00:00;09:00:00"] = true; The original array holds the values of the checkboxes on load of page, while current holds the values after the user has (potentially) made changes by selected one or more slots and clicks a button to submit. What I want to do is loop through both arrays comparing the values of the matching pairs and set a variable once one is found to be different. I tried two FOR loops but the length is coming out as zero(0). How can I do what i'm trying to do? var nothingChanged = false; for(var i = 0; i < originalTimeSlots.length; i++) { for(var j = 0; j < currentTimeSlots.length; j++) { if(originalTimeSlots[i] != currentTimeSlots[j]) { nothingChanged = true; return; } } }
  5. I have a page that displays time slots people can sign up for by selecting checkboxes input elements. for the <input> tag values, the "name"'s are the same, and the values are the date and time values of the time slot. When I submit this form to the server (and have selected two or more checkboxes), only the most recently checked checkbox is coming through on my $_POST variable when it gets to the server. Here's the code I have on the page for the checkbox imput (this is inside of a loop that executes from a specified earliest time show to a latest time shown) echo '<input type="checkbox" name="timeSlot" value="'.$date.';'.$startTime.';'.$endTime.'">'; Then server side I want to view all the checkboxes selected //get the time slots the faculty member checked to be available for advising $selectedTimeSlots = $_POST['timeSlot']; echo $selectedTimeSlots; So, for example, if I selected three checkboxes for the date 2008-11-17, for the times 8:00 AM-8:30 AM, 8:30 AM-9:00 AM, 9:00 AM-9:30 AM, the output of the variable server-side ($_POST['timeSlots']) is only the 9:00 AM-9:30 AM slot. What am I doing wrong or how can I make the file do what I want to do, which is to have a collection of ALL the selected timeSlots? Thanks in advance
  6. I have used PDO do make a generic method that I call to execute SQL queries to my database (myadvisor). I have been executing my queries pulling from the STUDENT and FACULTY tables within the myadvisor database. However, when we go to production, all the info from student and faculty will come from a seperate database (human_resources). I was wondering how to do (and how I will have to modify my code) to execute a query pulling from both the myadvisor and human_resources databases? In the following example of what I have currently, the APPT info will all come from the myadvisor database, while the student info will need to come from the human_resources database, where a.STUDENT would be a foreign key of human_resouces.students on the student's ID number. Thanks for the help in advance! function getAppointments($facultyId) { require_once('../includes/DatabaseManager.inc'); $dbManager = new DatabaseManager('localhost', 'myadvisor', 'guest', 'guest'); //build query $query = 'select a.APPT_DATE, a.APPT_START_TIME, a.APPT_END_TIME, a.STUDENT, s.STUD_F_NAME, s.STUD_M_NAME, s.STUD_L_NAME from ADVISING_APPOINTMENT a, STUDENT s where a.ADVISOR = :facultyId and a.STUDENT is not null and a.STUDENT = s.CWID order by a.APPT_DATE asc, a.APPT_START_TIME asc'; $queryHolders = array(':facultyId'); $params = array($facultyId); $paramTypes = array(PDO::PARAM_INT); $results = $dbManager->doPreparedStmt($query, $queryHolders, $params, $paramTypes); return $results; } class DatabaseManager { //-----------------// // CLASS VARIABLES // //-----------------// private $dbHost; private $dbName; private $dbUser; private $dbPass; //------------------------------------------------------------------- //--------------// // CONSTRUCTORS // //--------------// public function __construct($dbHost, $dbName, $dbUser, $dbPass) { $this->dbHost = $dbHost; $this->dbName = $dbName; $this->dbUser = $dbUser; $this->dbPass = $dbPass; } public function getDatabaseHost() { return $this->dbHost; } public function setDatabaseHost($value) {$this->dbHost = value; } public function getDatabaseName() { return $this->dbName; } public function setDatabaseName($value) {$this->dbName = value; } public function getDatabaseUser() { return $this->dbUser; } public function setDatabaseUser($value) {$this->dbUser = value; } public function getDatabasePassword() { return $this->dbPass; } public function setDatabasePassword($value) {$this->dbPass = value; } //------------------------------------------------------------------- //-----------// // FUNCTIONS // //-----------// /******************************************************************* Function: doPreparedStatement Creation Date: Created By: Parameters: Returns: Description: ********************************************************************/ function doPreparedStmt($query, $queryHolders, $params, $paramTypes) { //echo $query.'<br>'; try { //establish database connection $db = new PDO("mysql:host=$this->dbHost;dbname=$this->dbName", $this->dbUser, $this->dbPass); $stmt = $db -> prepare($query); //bind the specified parameters $counter = 0; foreach($queryHolders as $q) { $stmt -> bindParam($q, $params[$counter], $paramTypes[$counter]); //echo 'binding '.$q.' to value of '.$params[$counter].'<br>'; $counter += 1; } //execute the query and return all rows resulting from the query executed $stmt -> execute(); //echo $stmt -> rowCount(); return $stmt -> fetchAll(); } catch(PDOException $e) { echo $e->getMessage(); } //finally close statment and database connection $stmt -> close(); $db = null; } //------------------------------------------------------------------- }//end class
  7. I'm using PDO and trying to bind a date parameter. For example, my parameter is '2008-08-08' and I'm trying to set that as a parameter for more query but I get "Fatal error: Undefined class constant 'PARAM_DATE' ". Any ideas why I would be getting this error? Should I just pass the date as a STR type? Would MySQL convert that to a DATE automatically, as that's what the column type in the DB is? (NOTE: i have a $dbManager object that handles my connection and loops through binding parameters, etc) $query = 'update ADVISING_APPOINTMENT a set a.STUDENT = null where a.STUDENT = :studentId and a.APPT_DATE = :apptDate and a.APPT_START_TIME = :apptStartTime and a.APPT_END_TIME = :apptEndTime'; $queryHolders = array(':studentId', ':apptDate', ':apptStartTime', 'apptEndTime'); $params = array($studentId, $apptDate, $apptStartTime, $apptEndTime); $paramTypes = array(PDO::PARAM_INT, PDO::PARAM_DATE, PDO::PARAM_TIME, PDO::PARAM_TIME); $results = $dbManager->doPreparedStmt($query, $queryHolders, $params, $paramTypes);
  8. Ok this was my code before: foreach($results as $row) { if($counter % 2 == 0) echo '<tr>'; else echo '<tr class="lightGrey">'; $counter += 1; echo '<td>'.$row['course_name'].' </td>'; echo '<td>'.$row['term_1_grade'].' </td>'; echo '<td>'.$row['term_2_grade'].' </td>'; echo '<td>'.$row['mid_term_exam'].' </td>'; echo '<td>'.$row['semester_1_grade'].' </td>'; echo '<td>'.$row['term_3_grade'].' </td>'; echo '<td>'.$row['term_4_grade'].' </td>'; echo '<td>'.$row['final_exam'].' </td>'; echo '<td>'.$row['semester_2_grade'].' </td>'; echo '<td>'.$row['course_grade'].' </td>'; echo '</tr>'; } And this is my code after, and now the table is not formatted, it's just outputting the vaules all together outside of the table, instead of in the table in the cells: foreach($results as $row) { if($counter % 2 == 0) echo '<tr>'; else echo '<tr class="lightGrey">'; $counter += 1; echo '<td>'.(!empty($row['course_name'])) ? $row['course_name'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_1_grade'])) ? $row['term_1_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_2_grade'])) ? $row['term_2_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['mid_term_exam'])) ? $row['mid_term_exam'] : ' '.'</td>'; echo '<td>'.(!empty($row['semester_1_grade'])) ? $row['semester_1_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_3_grade'])) ? $row['term_3_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['term_4_grade'])) ? $row['term_4_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['semester_2_grade'])) ? $row['semester_2_grade'] : ' '.'</td>'; echo '<td>'.(!empty($row['course_grade'])) ? $row['course_grade'] : ' '.'</td>'; echo '</tr>'; } Any way to fix this so that it works via the second method?
  9. i'm building a HTML table base don the contents of a database row returned from a mysql PDO query. I have some columns that don't have data in them every time, and in the table it doens't put data in the cell and therefore messes up the look of the table because the border for the cell with missing data doesn't get output. I can fix the problem by putting whitespace in teh cell. Right now i have the following line: echo '<td>'.$row['course_name'].' </td>'; What I'd like to do is some one-liner like the following, that if the column contains no data echoes the whitespace char, otherwise the data in the column. Does anyone if this is possible and if so how to do it? echo (!empty($row['course_name']) ? $row['course_name'] : '$nbsp;';
  10. Below is like what i had in mind, but it doesn't work: function doPreparedStatement($query, $paramTypes, $params, $resultColumns) { $stmt = $db -> prepare($query); foreach($params as $param) $paramString += ', '.$param; $stmt -> bind_param($paramTypes, $paramString); $stmt -> execute(); $stmt -> store_result(); foreach($resultColumns as $resultCol) $resultColString += $resultCol.', '; $resultColString = substr($resultColString, 0, -2); $stmt -> bind_result($resultColString); return $stmt; }
  11. By a number of parameters, I mean that I want to be able to do one query like SELECT name FROM users as: $query = 'SELECT name FROM users WHERE name = ?'; $paramTypes = 's'; $params = array($name); $resultCols = array ($resultName); doPreparedStmt($query, $paramTypes, $params, $resultCols); and then be able to use the same function for a prepared stmt with two, three, four, etc parameters, such as: $query = 'SELECT state FROM operations WHERE state = ? AND city = ?'; $paramTypes = 'ss'; $params = array($state, $city); $resultCols = array ($resultState, $resultCity); doPreparedStmt($query, $paramTypes, $params, $resultCols);
  12. I'm trying to make a generalizing function to execute a MySQL prepared statement, and pass as arguments to the function the query to be executed, the bind_params data types string, the variables of the parameters to bind, and the bind_result names to bind the resulting columns to variables. I was thinking of passing each of these as arrays, and doing some type of looping through the arrays to build the actual statement(i.e., foreach($bindParam as $param), etc). The below code is wat I'm trying to make as a function. Then i'd like to pass the value of $query, "sss" (or w/e data types) of bind_param, each of the parameters, and each of the bind_result fields. require_once('db_fns.php'); if( $db = openConnection('guest', 'guest') ) { $query = 'SELECT m.member_id, password, member_type FROM member m WHERE m.member_id = ? and password = ? and member_type = ?'; //build and execute query session_start(); $stmt = $db -> prepare($query); $stmt -> bind_param("sss", $_SESSION['validUserId'], $_SESSION['validUserPassword'], $_SESSION['validUserType']); $stmt -> execute(); $stmt -> store_result(); $stmt -> bind_result($userid, $password, $validUserType); $numRows = $stmt -> num_rows; //do whatever is needed //otherwise user has permisson to access this directory //close prepared statement and database connection $stmt -> close(); closeConnection($db); With the parameters and the result columns, is there any way to make the function generic enough to be able to handle any number of parameters/columns? I was thinking something like, the following, if possible, but I dont know how to implement the actually doPreparedStmt() function: $query = 'SELECT m.member_id, password, member_type FROM member m WHERE m.member_id = ? and password = ? and member_type = ?'; $paramTypes = 'sss'; $params = array($_SESSION['validUserId'], $_SESSION['validUserPassword'], $_SESSION['validUserType']); $resultColumns = array($userid, $password, $validUserType); doPreparedStmt($query, $paramTypes, $params, $resultColumns); code]
  13. That fetch() line did it; thanks to everyone!
  14. I kno the database is populated. It has only the one entry which i'm testing. Also, the userid and password variables are being set (although they could still be set from the code prior to bind_result). I did a check and the bind_result line is returning 1/true....any other ideas as to what's going wrong?
  15. I have a table in my database(USERS), with three fields MEMBER_ID, PASSWORD, and USER_TYPE. I'm trying to store the results of the query and then need to redirect to a different directory based on the result's USER_TYPE. I've tried using bind_result() and then doing a switch off of $usertype, but apparently $usertype isn't populated. What am I doing wrong, or is there a better way to do this? function validateUser($userid, $password) { //attempt database connection to execute query and attempt match with userid and password require('db_fns.php'); if( $db = openConnection('guest', 'guest') ) { //build and execute query $stmt = $db -> prepare('SELECT member_id, password, user_type FROM users WHERE member_id = ? AND password = ?'); $stmt -> bind_param("ss", $userid, $password); $stmt -> execute(); $stmt -> store_result(); $num_rows = $stmt -> num_rows; //if no match occurred, userid and/or password user entered are NOT valid in the database //set error message and return to login page if($num_rows == 0) { session_start(); $_SESSION['errorMsg'] = 'user ID and/or password or incorrect; Please try again'; header('Location: ./'); } //if a match has occurred, the user is a valid user; get the user's type and //assign validUserId, validUserPassword, validUserName, validUserType SESSION variables else if ($num_rows >= 1) { //TODO $stmt->bind_result($userid, $password, $usertype); echo $userid; echo $password; echo $usertype; } //close prepared statement and database connection $stmt -> close(); closeConnection($db); } }
  16. $pages = array ( 'home' => 'home.php', 'about' => 'about.php', 'performances' => 'performances.php', 'contact' => 'contact.php'); if( !isset($_POST['page']) ) $page = 'home'; else $page = $_POST['page']); include($pages[$page]);
  17. That's what I have. sorry i dont have the code in front of me so I wrote it up and made that typo. The value of $page is stored correctly (verified via echo). The problem is occurring with the keys/array on the include() line. For exampe include($page.'.php'); work fine, but include($pages[$page]); is giving the undefined index error.
  18. I've got an array of pages on in my site, which the key gets set based on the button clicked and stored in a POST variable $page which comes from my navigation menu which is a form that gets submitted on button click, and i'm trying to do an include() with the $page value matched with an the array of pages, but I'm getting and "undefined index" error. I know the pageName variable is set correctly and it works fine if i manually enter into the include what i'm trying to build (i.e. manually doing include('home.php'); ). Anyone know that the problem could be? $page = $_POST('pageName'); $pages = new array ('home' => 'home.php', 'about' => 'about.php' ); include( $pages[$page] );
  19. Perhaps I didn't word my question well. I'm not referring to how to make a query that ignores NULLs, but a configuration setting that when MySQL outputs the results of a query it outputs a blank space instead of NULL where a value is null. I'll provide an example. I've seen someone who had their MySQL set up this way, same version I'm using, but that person no longer works with me. Currently +-------------+--------+-----------+------------+ | idtesttable | school | readscore | mathscore | +-------------+--------+-----------+------------+ | 1 | A | 60 | 50 | | 2 | A | 40 | NULL | | 3 | A | NULL | 70 | | 4 | B | 40 | NULL | | 5 | B | NULL | 50 | +-------------+--------+-----------+-----------+ Desired Currently +-------------+--------+-----------+------------+ | idtesttable | school | readscore | mathscore | +-------------+--------+-----------+------------+ | 1 | A | 60 | 50 | | 2 | A | 40 | | | 3 | A | | 70 | | 4 | B | 40 | | | 5 | B | | 50 | +-------------+--------+-----------+-----------+
  20. Is there a way to make MySQL not show null values when displaying the results of a query from the command line? Like for values that are NULL instead of writing NULL jus hav it be blank?
  21. Anyone know how to center the text in a textfield? I've tried align="center" but that doens't seem to be doing it.
  22. After using print_r($row) i verified the result set is correct. I tried changing each attribute to caps, i.e. $row['SCHOOL_NAME']; and the code now works. I didn't thing the mysqli commands were case sensitive, but I gues that a newbie mistake Thanks to all who hav replied and helped with solving the issue.
  23. I figured out the getting the values from the combo boxes directly and am now longer using the hidden variables on the form, I'm pulling the selected value out of the select box directly. The query is now formatted correctly, and I'm also returning the correcty number of resulting rows (verified via the echo $num_rows), however, I'm still getting an "Undefined index" error on each of the $row[attribute] output calls, which puts me close to where i stared originally with this page. What am I doing wrong it outputting each column's data from the result set's rows? //if a search type was selected, else test to see which type of search //was specified and set the query accordingly if(isset($_POST['searchType'])) { //determine the syntax of the query based on search type selected $selected_radio = $_POST['searchType']; if ($selected_radio == 'searchByName') $query = "select * from school_data where school_name = '".$_POST['schoolNames']."'"; else if ($selected_radio == 'searchByDistrict') $query = "select * from school_data where school_district = '".$_POST['schoolDistricts']."'"; //execute the appropriate query to obtain a result set echo $query; $results = db_query('guest', 'guest', $query); //otherwise loop through results and output information $num_results = $results -> num_rows; echo $num_results; for($i=0; $i < $num_results; $i++) { $row = $results -> fetch_assoc(); echo '<tr>'. '<td>'.$row['school_name'].'</td>'. '<td>'.$row['school_district'].'</td>'. '<td>'.$row['city'].'</td>'. '<td>'.$row['state'].'</td>'. '<td>'.$row['mascot'].'</td>'. '<td>'.$row['school_colors'].'</td>'. '</tr>'; } }
  24. yes that's correct i noticed that after my last post; however, I dont think that's the issue as i'm still getting the problem having replacted the + signs with dots. The issue appears to be not correctly getting the value from the hidden variable (selectedSchool/selectedDistrict). I put in echo $selectedSchool and nothing is output (even with a school selected in my drop-down select also put in echo $query and the what got output was select * school school_data where school_name = " and that's it no value and no closed quote, and that should also be a single quote i believe quoting the value
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.