Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
BOOK: PHP and MySQL 24-Hour Trainer
This is the forum to discuss the Wrox book PHP and MySQL 24-Hour Trainer by Andrea Tarr ; ISBN: 978-1-1180-6688-1
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: PHP and MySQL 24-Hour Trainer section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old September 13th, 2012, 12:23 AM
Registered User
Points: 43, Level: 1
Points: 43, Level: 1 Points: 43, Level: 1 Points: 43, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 7
Thanks: 1
Thanked 1 Time in 1 Post
Default 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

HERE IS THE STACK-TRACE


( ! ) 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


OUTPUT:
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 ?
  #2 (permalink)  
Old September 13th, 2012, 11:42 PM
Registered User
Points: 43, Level: 1
Points: 43, Level: 1 Points: 43, Level: 1 Points: 43, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2012
Posts: 7
Thanks: 1
Thanked 1 Time in 1 Post
Default

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
  #3 (permalink)  
Old December 7th, 2012, 09:06 PM
Registered User
Points: 3, Level: 1
Points: 3, Level: 1 Points: 3, Level: 1 Points: 3, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

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:

Code:
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:

Code:
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.

Last edited by null; December 8th, 2012 at 06:59 AM..


Similar Threads
Thread Thread Starter Forum Replies Last Post
Lesson 28 Passwords JoyH BOOK: PHP and MySQL 24-Hour Trainer 2 April 5th, 2012 12:06 PM
NerdDinner Dinner.cs errors (System.ComponentModel.DataAnnotations?) LorenMaxwell BOOK: Professional ASP.NET MVC 2 1 January 2nd, 2011 04:12 AM
Chap 29, Listing 29-7, Page 1305 kiwibrit BOOK: Professional ASP.NET 3.5 : in C# and VB ISBN: 978-0-470-18757-9 1 September 11th, 2009 05:53 AM
Single Typo in 'Final' VB Code - causes 37 errors irelandk BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 May 3rd, 2009 02:30 PM
Drag & drop Errors jjustin BOOK: Professional JavaScript for Web Developers ISBN: 978-0-7645-7908-0 0 August 25th, 2006 09:21 AM





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