wesmith4
Members-
Posts
36 -
Joined
-
Last visited
Everything posted by wesmith4
-
I used script 10.5 as a model for view_households.php but get he following error message: ------------ warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /home/content/00/10035700/html/pumc/edit_household.php on line 97 This page has been accessed in error without valid hh_id -------------------- <?php # Script 10.5 - #5 // This script retrieves all the records from the users table. // This new version allows the results to be sorted in different ways. session_start();// access session variables. $page_title = 'View the Current Households'; include ('includes/header.html'); echo '<h1>Registered Users</h1>'; require ('includes/mysqli_connect.php'); // Number of records to show per page: $display = 10; // Determine how many pages there are... if (isset($_GET['p']) && is_numeric($_GET['p'])) { // Already been determined. $pages = $_GET['p']; } else { // Need to determine. // Count the number of records: $q = "SELECT COUNT(hh_id) FROM Households"; $r = @mysqli_query ($dbc, $q); $row = @mysqli_fetch_array ($r, MYSQLI_NUM); $records = $row[0]; // Calculate the number of pages... if ($records > $display) { // More than 1 page. $pages = ceil ($records/$display); } else { $pages = 1; } } // End of p IF. // Determine where in the database to start returning results... if (isset($_GET['s']) && is_numeric($_GET['s'])) { $start = $_GET['s']; } else { $start = 0; } // Determine the sort... // Default is by last name. $sort = (isset($_GET['sort'])) ? $_GET['sort'] : 'ln'; // Determine the sorting order: switch ($sort) { case 'ln': $order_by = 'LastName ASC'; break; case 'fn': $order_by = 'FirstName ASC'; break; default: $order_by = 'LastName ASC'; $sort = 'ln'; break; } // Define the query: $q = "SELECT LastName, FirstName, hh_id FROM Households ORDER BY $order_by LIMIT $start, $display"; $r = @mysqli_query ($dbc, $q); // Run the query. // Table header: echo '<table align="center" cellspacing="0" cellpadding="5" width="75%"> <tr> <td align="left"><b>Edit</b></td> <td align="left"><b>Delete</b></td> <td align="left"><b><a href="view_users.php?sort=ln">Last Name</a></b></td> <td align="left"><b><a href="view_users.php?sort=fn">First Name</a></b></td> //<td align="left"><b><a href="view_users.php?sort=rd">Date Registered</a></b></td> </tr> '; // Fetch and print all the records.... $bg = '#eeeeee'; while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) { $bg = ($bg=='#eeeeee' ? '#ffffff' : '#eeeeee'); echo '<tr bgcolor="' . $bg . '"> <td align="left"><a href="edit_household.php?id=' . $row['hh_id'] . '">Edit</a></td> <td align="left"><a href="delete_household.php?id=' . $row['hh_id'] . '">Delete</a></td> <td align="left">' . $row['LastName'] . '</td> <td align="left">' . $row['FirstName'] . '</td> //<td align="left">' . $row['dr'] . '</td> </tr> '; } // End of WHILE loop. echo '</table>'; mysqli_free_result ($r); mysqli_close($dbc); // Make the links to other pages, if necessary. if ($pages > 1) { echo '<br /><p>'; $current_page = ($start/$display) + 1; // If it's not the first page, make a Previous button: if ($current_page != 1) { echo '<a href="view_Households.php?s=' . ($start - $display) . '&p=' . $pages . '&sort=' . $sort . '">Previous</a> '; } // Make all the numbered pages: for ($i = 1; $i <= $pages; $i++) { if ($i != $current_page) { echo '<a href="view_Households.php?s=' . (($display * ($i - 1))) . '&p=' . $pages . '&sort=' . $sort . '">' . $i . '</a> '; } else { echo $i . ' '; } } // End of FOR loop. // If it's not the last page, make a Next button: if ($current_page != $pages) { echo '<a href="view_households.php?s=' . ($start + $display) . '&p=' . $pages . '&sort=' . $sort . '">Next</a>'; } echo '</p>'; // Close the paragraph. } // End of links section. include ('includes/footer.html'); ?> ----------------------- When I run "view_households.php" I see the table of records. When I click the EDIT link it displays "edit_households.php" with ....php?id.... But then I get the error that no valid hh_id is available. I would appreciate any help. I have been struggling with this for days. Thanks in advance. Wes Smith
-
The code below produces a syntax error, saying there is unexpected T-String in the line that starts with "Load Data......". Can anyone tell me wyat I am doing wrong? ========================================= <?php require ('./mysqli_connect.php'); LOAD DATA LOCAL INFILE 'c:/Users/CourseOfStudy.txt' INTO TABLE CourseOfStudy FIELDS TERMINATED BY ',' IGNORE 1 LINES; ?> ======================================== Thanks for any directions for a new user. Wes Smith
-
The script in 12.12 uses a session to record the id number of a user listed in the users table. The script identifies data from two columns or fields in the user table. An integer in the field user_id is assigned to $_SESSION['user_id']. But the value of $_SESSION['user_id'] created in this script, is a string, not an integer! I planned to use the value of this integer to query the table, but I can not use this string. Clearly I am new to PHP/MYSQL. If anyone can help me determine what I am doing wrong or how to extract the number (not a string) using the script of chapter12, it would be greatly appreciated. Wes Smith wesmith4@gmail.com
-
Here is more details about my problems using PHP sessions: 1 <?php # Script 10.1 - view_one_students_report_copy.php 2 // This script retrieves the grades for students. 3 session_(); 4 $page_title = 'View Your Courses And Grades.'; 5 // include ('includes/headerStuReport.html'); 6 require ('./mysqli_connect.php'); 7 echo "session number =".$_SESSION[user_id']; 8 // Define the query: 9 $q = "SELECT * FROM TranscriptView WHERE StudentID = {$_SESSION['user_id']}"; 10 $r = @mysqli_query ($dbc, $q); 11 12 // Count the number of returned rows: 13 $num = mysqli_num_rows($r); 14 15 ?> ===================================================== 1st: I run the query(line 9) in using PHP MYADM. There is no problem. 2nd: When I run the short code above, I get the following error: Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING, expecting ']' in /home/content/00/10035700/html/view_one_students_report_copy_copy.php on line 9 I don't understand what I am doing wrong. Any help would be appreciated! Wes Smith wesmith4@gmail.com
-
See script 12.12 from the 4th edition. This login.php script sets some session data. on line 19-> $_SESSION['user_id'] = $data['user_id]; In another script I retrieve information in a query using a WHERE clause containing $_SESSION['user_id']. But it does not work. Here is some of the code: </php script view students grades. session_start(); require ('./mysqli_connect.php'); $q = "SELECT * FROM TranscriptView WHERE studentID = $_SESSION['user_id']; $r = @mysql_query ($dbc, $q); $num = mysqli_num_rows($r); But the variable $num is not one. The routine fails at this point It is like the session variable is a string, not an integer! Can anyone provide me with direction? Wes Smith
-
I am new to using PHP and MySQL. Previously used MS Access. One ability in creating a query in Access was very helpful to me. I am asking if something like it is available in PHP-MySQL. Here is a query designed for use in MS Access: ------------ SELECT tblCourses.[ClassID], tblCourses.[Coursename], tblCourses.[TeaLastname], tblCourses.[TeaFirstname] FROM tblCourses WHERE (((tblCourses.[TeaLastname])=[Enter teacher's last name:])); ------------ This query allowed the user of the query to input a teacher's last name and then receive all the data for the courses taught by that teacher. Can anyone tell me how to accomplish this using PHP and MySQL? I would appreciate any guidance or assistance. Thank you. Wes Smith
-
Code adapted from Larry Ullman's book, in chapters 10 through 12 (PHP and MYSQL). <?php # Script 10.1 - view_coursegrades.php // This script retrieves the grades for students. // This version links to edit and delete pages. // Session added 6/29/2013 Session_Start; echo session_id(); echo "TeacherId=" . $_SESSION['user_id']; $page_title = 'View Course Grades.'; include ('includes/header.html'); // echo '<h1>Course Grades at ASMWA</h1>'; require ('./mysqli_connect.php'); // Define the query: $q = "SELECT StudentID, StudentIDfk, CourseID, CourseIDfk,COSID, LastName, FirstName, CourseTitle, Term, GradeEarned, Institution, TermYear, TermNumber, TeacherIDfk FROM CourseOfStudy, Courses, Students WHERE Students.StudentID = CourseOfStudy.StudentIDfk AND Courses.CourseID = CourseOfStudy.CourseIDfk AND TeacherIDfk = $_SESSION['user_id']"; $r = @mysqli_query ($dbc, $q); When I run the script above, I get the following error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/content/00/10035700/html/view_coursegrades.php on line 15. Line 15 is in red above (query). The query works if a known number is used instead of the global variable: $_SESSION['user_id']. There is something wrong involving the session variable for user_id, which is an integer. If anyone can point out the error of my ways, I appreciate all assistance. Wes Smith
-
I am using the script Login.php from the book and a version of strings.php to test viewing the session variables. But I can not show $_SESSION['user_id'] for some reason. Can anyone help me understand what I am doing wrong? --------------------- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:la"en" lang="en"> session_start(); <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Strings</title> </head> <body> <?php # Script 1.6 - strings.php // Create the variables: $first_name = 'Willie'; $last_name = 'Smith'; $var = $_SESSION['user_id']; //Print the values: echo "<P>The names are $first_name and $last_name and $var.</p>"; ?> </body> </html> ----------------- I appreciate any help understanding the use of SESSIONS. Wes Smith
-
I am new at using PHP and MySQL. I am using a login.php script from Larry's book, and a similiar script I call view_coursegrades.php. I want to be able to identify a teacher who logs into my site, and then use a query based on that identification to allow them to edit and view grades in only the courses where they are the teacher. The following is some of the script: <?php # Script 12.12 - login.php #4 // This page processes the login form submission. // The script now stores HTTP_USER_AGENT value for added security. // Check if the form has been submitted: if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Need two helper files: require ('includes/login_functions.inc.php'); require ('./mysqli_connect.php'); // Check the login: list ($check, $data) = check_login($dbc,$_POST['email'], $_POST['pass']); if ($check) { // OK! // Set the session data: session_start(); $_SESSION['user_id'] = $data['user_id']; $_SESSION['first_name'] = $data['first_name']; // Store the HTTP_USER_AGENT: $_SESSION['agent'] = md5($_SERVER['HTTP_USER_AGENT']); // Redirect: redirect_user('loggedin.php'); } else { // Unsuccessful! // Assign $data to $errors for login_page.inc.php: $errors = $data; } mysqli_close($dbc); // Close the database connection. } // End of the main submit conditional. // Create the page: include ('includes/login_page.inc.php'); ?> ====================================== <?php # Script 10.1 - view_coursegrades.php #3 // This script retrieves the grades for courses. // This version links to edit and delete pages. session_start(); //Access the existing session. echo '<h2>The number below is for teacher ID.</h2>'; echo '<h2>{$_SESSION['user_id']}</h2>'; $page_title = 'View Course Grades.'; include ('includes/header.html'); echo '<h1>Course Grades at ASMWA</h1>'; require ('./mysqli_connect.php'); // Define the query: $q = "SELECT COSID,LastName,FirstName,CourseTitle,TeaLastName, TeacherID, GradeEarned FROM TranscriptView"; $r = @mysqli_query ($dbc, $q); // Count the number of returned rows: $num = mysqli_num_rows($r); =================================== I have been unable to filter the query to select only records from the database where the TeacherID is for the teacher who logged in. Can anyone help me? Wes Smith
-
In running a script to "REGISTER USERS" for my database hosted by GODADDY, I get the following message after attempting to register a user: "Could not connect to MySQL:Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock'. I downloaded the script(s) from the site. I would appreciate any advice. wesmith4