p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: PHP and MySQL 24-Hour Trainer (http://p2p.wrox.com/forumdisplay.php?f=659)
-   -   Errors LESSON CS 28 & 29 FINAL (http://p2p.wrox.com/showthread.php?t=88435)

MRGLENN September 13th, 2012 12:23 AM

Errors LESSON CS 28 & 29 FINAL
Downloaded Code on Lessons 28 and
Made The Changes Recomended in Thread about Errors, on Lesson 28 .

The 'contact' Table is Showing all users & Passwords after running install.sql

I. Getting this Error after Entering Login: User ID 'msmith' & Password 1234

which Reports a Error at Line 422 at File: contact.php


( ! ) Fatal error: Call to a member function fetch_array() on a non-object in C:\xampp\htdocs\php24\lesson28csfinal\includes\cla sses\contact.php on line 422
Call Stack
# Time Memory Function Location
1 0.0015 340184 {main}( ) ..\index.php:0
2 0.0026 384272 require_once( 'C:\xampp\htdocs\php24\lesson28csfinal\includes\in it.php' ) ..\index.php:13
3 0.0569 464048 userLogin( ) ..\init.php:32
4 0.0725 572320 Contact::logIn( array(2) ) ..\functions.php:223
5 0.1051 591168 Contact::getContactIdByUser( string(6) ) ..\contact.php:488

The Error Seems to Be at This Line ..... in: contact.php

while($result = $result_obj->fetch_array(MYSQLI_ASSOC)) {
$id = $result['id'];

I Placed a echo Statement To Display the $result_obj & $query.... My Line may be different Here as I added Comments

To Show the Variable $result_obj & $query ....It Appears to Be Empty for $result_obj

The $query appears Correct ....Shown Below

Just Before Line 424 in contact.php...result_Obj: query: SELECT id FROM `contacts` WHERE user_name="msmith" LIMIT 1

It Appears this is Causing the Error . It Cant Locate=> fetch_array () with the

Ptr result_object being a Null.

Q: Could you Recommend How To Correct Errors HERE in Lesson 28-29cs Final Solutions ?

MRGLENN September 13th, 2012 11:42 PM

Found Problem with 'smithside' DataBase (Lesson 28csFinal)

The Table: 'contacts' was Not Updated on: 3 Additional Fields

==>: User Name , Password , and Access (Were Missing)

Ran: install.sql

in the: phpMyAdmin Tool a 2nd Time , To: Update the Table(s)

The Errors are Gone

null December 7th, 2012 09:06 PM

As I don't see a point in creating a new thread I'm just gonna post my doubts here, hope you don't mind MRGLENN.

My problem is even after I have added the 3 colums to the 'contacts' table (user_name, password and access) I'm still having difficulties putting the example to work.

The first problem is within the _verifyInput() function in the Contact class.
When I edit a contact to change a password it enters in the following elseif statement in the function:


elseif (self::getContactIdByUser(trim($this->user_name))) {
    $error = true;

therefore assigning true to $error and not allowing me to update the existing contact information.

The other problem is when I create a new contact and give an username and password for it all the existing contacts in the table will also have their user_name and password fields changed to the username and password I provided for the new contact.

I think it's happening this way due to the following code, in the addRecord() function:


if ($connection->query($query)) { // this inserts the row
        // update with the user name and password now that you know the id
        $query = "UPDATE contacts
        SET user_name = '" . Database::prep($this->user_name) . "',
        password = '" . hash_hmac('sha512',
          $password . '!hi#HUde9' . mysql_insert_id(),
          SITE_KEY) ."',
        access = '" . Database::prep($this->access) . "'";

because even though it is said it will update with the username and password now that the ID is known, we're not setting a WHERE clause to edit only that specific row, causing all the contact rows to be updated to the user_name and password values I entered for the new contact.

If anyone could point me in the right direction with these points, I'd appreciate it.

Thanks in advance

EDIT: This way already addressed in another thread, probably should have searched first. Here's the link for the correction.

All times are GMT -4. The time now is 10:30 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.