O'Reilly Forums: Chapter 7 - O'Reilly Forums

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Chapter 7 Pages 345 - 371

#1 User is offline   andy2012 

  • New Member
  • Pip
  • Group: Members
  • Posts: 2
  • Joined: 23-January 12

Posted 11 July 2014 - 06:17 AM

Hi,

Sorry for the long post. I am just laying out how I approached the Chapter 7 project and what I came across. I got some solutions but others I can't fix and need help.

Note: Database mismatch_db was created and populated with supplied mismatch_user.sql details, downloaded supplied files for the chapter, using Initial folder.


Page 350: Tinker with the Mismatch application
The index.php page loads successfully.

On clicking View Profile link I get the following errors:
- Notice: Undefined variable: user_id in C:\wamp... on line 21
- Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in C:\wamp... on line 28

On clicking Edit Profile link I get the following error:
- Notice: Undefined variable: user_id in C:\wamp... on line 92

Worked on with the lesson assuming these errors would rectify themselves on following the books instructions.

---

Page 354: Encrypt Passwords with SHA()
Since Johan Nettles already exists - given in mismatch_user.sql why are we inserting a new record and having two instances of Johan? I choose to update the existing record. At this point I get 1 warning in MySQL - Data Truncated for column 'password' at row 11. Should be fine once I move to page 355.

update mismatch_user SET username = 'jnettles', password = SHA('tatlover') WHERE first_name = 'Johan';


---

Page 355: Making room for encrypted password
Altered the table
Ran the update statement once again:
update mismatch_user SET username = 'jnettles', password = SHA('tatlover') WHERE first_name = 'Johan';


No problems - I can find Johan Nettles and his password - the record exists.

---

Page 362: Test Drive
Ran the index.php script and logged in as jnettles, tatlover, all fine - the HTTP Authentication worked ;-)

Clicked the view profile link, all fine.

Clicked the edit profile link and edited jnettles account (changed Birthdate to 1980-10-02).

On clicking the "save profile" button I get the following errors:
- Notice: Undefined variable: user_id in C:\wamp... on line 23
- getimagesize() [function: getimagesize]: Filename cannot be empty in C:\wamp... on line 34

On clicking the "view your profile" button it shows the new Birthdate did not stick.

At this point I updated the editprofile.php page with the following:

Changed:

list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);


To this:
if (!empty($new_picture)) {
  list($new_picture_width, $new_picture_height) = getimagesize($_FILES['new_picture']['tmp_name']);
}



I found this solution in the head first forum ;-)

Closed all pages and reopened index.php in the browser.
Logged in once again as jnettles successfully.

On clicking the "view profile link"
- Showed jnettles page - all fine

On clicking the "edit your profile link" viewprofile.php page made a change, now get only 1 error as follows:
- Undefined index: user_id in C:\wamp... on line 23

It also tells me the profile has been successfully update.


On clicking the "view your profile link"
- The updated information did not stick.


Went back and decided to change edit jnettles profile picture. A new error appears Notice:
- undefined index: file in C:\wamp... on line 44.

Changed line 44 editprofile.php:
if ($_FILES['file']['error'] == 0) {


To this line instead:
if ($_FILES['new_picture']['error'] == 0) {



It worked the error no longer appears.

I found this solution in the head first forum ;-)

However, the updated information will not stick and still getting the undefined index for user_id error.

----

I am attaching the files, can anyone help with these final two errors?

Item 1: - Undefined index: user_id in C:\wamp... on line 23 (editprofile.php)
Item 2: - any updates will not stick and reverts to old information (viewprofile.php)

Thanks for any help.

Andy ;-)

Attached File(s)


0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users