wesmith4
-
Posts
36 -
Joined
-
Last visited
Posts posted by wesmith4
-
-
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
-
Wow, Margaux! That fixed it.
Thank you so much.
Wes
-
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
Chapter 10 Edit A Record: View.... --> Edit
in PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
Posted
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