How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask TheDoctor Your Own Question

TheDoctor
TheDoctor, Professional w/Adv. Degree
Category: Homework
Satisfied Customers: 1524
Experience:  M.S. in Internet Information Systems
59032869
Type Your Homework Question Here...
TheDoctor is online now
A new question is answered every 9 seconds

PHP/MySQL: Need debugging help on 2 pages. Adding books to

Resolved Question:

PHP/MySQL: Need debugging help on 2 pages. Adding books to tables in a database and editing book data of tables in a database. Will be using INSERT and UPDATE into 3 tables. I have four other pages similar but I believe if I can get two to work, I can use that information in the other four.


 


Specifics: Using a php form and code to add information to a MySQL database and to edit information in a MySQL database.

Submitted: 1 year ago.
Category: Homework
Expert:  Technology Homework Tutor replied 1 year ago.
Hi my name isXXXXX for using JustAnswer. Can you provide the code you are working with? Thanks.
Customer: replied 1 year ago.

Yes, I can provide code and database dump. Should I attach it here?

Expert:  Technology Homework Tutor replied 1 year ago.
Paste it at pastebin.com and paste the URL of the upload here that way all of the code can be seen. Thanks.
Expert:  TheDoctor replied 1 year ago.
Hello,

This appears to be for a course or homework assignment.

Can you please confirm.

Thank you
Customer: replied 1 year ago.

yes

Expert:  TheDoctor replied 1 year ago.
Hello again,

Think you for confirming. We will need to move the question into the homework category. I can assist you with this.

Zip up your code and database dump. You can either attach it to this thread or upload it to http://ge.tt

Once uploaded, you will be given a link on the right. Click on the 'Copy Link' option and then paste it here.

Once I have your files, I will be able to assist you.

Thank you
Customer: replied 1 year ago.

There is already someone else helping me - Eljon. Is he still helping? I just sent him the code a few minutes ago.

Expert:  TheDoctor replied 1 year ago.
You didn't actually upload the code. You would have had to paste the URL into this thread, which you did not do.

The other professional does not work in the Homework category. However, I am a Zend Certified Engineer (PHP Expert) with many years of experience and can certainly provide you with assistance.
Expert:  Technology Homework Tutor replied 1 year ago.
I'm still here. Waiting for you to send the code.
Customer: replied 1 year ago.

Did you get it that time?

Customer: replied 1 year ago.

pastebin.com/HXGPJvmJ

 

http://ge.tt/9PFPHde/v/0?c

Expert:  TheDoctor replied 1 year ago.
Hello again,

Thank you for providing the code. I will contact you once I am done debugging everything.

Thank you
Customer: replied 1 year ago.

okay, thank you


 


you can also find the Web site this code is being used on at


 


kimcoxdesigns.com

Expert:  TheDoctor replied 1 year ago.
Hello again,

Can you please also send me the included files? It is very difficult to debug a file when it has a number of includes that I do not have. I have no way of knowing any of them are behaving badly.

Your addBook.php file includes:

header.html
config.php
connect.php
footer.html

For instance, without these files I will always get "You must be logged in..." I can comment all of that code out, but then I am not really testing what you have.
Customer: replied 1 year ago.

new file with includes folder is at http://ge.tt/8TSTKde/v/0?c

Expert:  TheDoctor replied 1 year ago.
Thank you so much. I will contact you soon.
Expert:  TheDoctor replied 1 year ago.
Hello again!

So, I had to make some changes in order to get this to work correctly:

You can download the files here:


First, please notice that there is a file called alters.sql

This file contains statements that you need to run on your database.

Here was the issue. An author or a publisher can have more than one book. So putting a bookID in the authors or the publisher table is not good and will lead to many issues. Additionally, the way you were attemptint to perform inserts on those tables will never work.

Once you have run all of that SQL, you will be ready to use the changed files.

I changed the queries in each file to make certain that both the add and edit functionality works.

You had a minor issue where you were calling mysql_error when you are using mysqli. I corrected those for you.

The code should be pretty self-explanitory. Take note of the ON DUPLICATE KEY UPDATE statements. This states that if the author or the publisher already exists, we just want to get the ID of the existing author or publisher. That way, if you enter the name of an author or a publisher that is already in the database, the book will be associated to the existing records rather than create new ones.

You can immediately see the edit page work by tyin the URL in as "editBooks.php?id=1"

However, if you have a page somewhere that lists books, it probably isn't going to work after the database changes because of the change to the way that books are associated to authors and publishers. To fix this, go into editBooks.php and look at lines 130 - 141. This is the select statement to get the book information now that the tables have been corrected. Actually, the way that you had the tables was a violation of Normal Form, so if I hadn't fixed them, your instructor probably would have said something.

Let me know if you have any questions. I'm here to help.

Please remember to rate my answer. Thank you so much!
Expert:  TheDoctor replied 1 year ago.
Hello again, Kim!

I wanted to let you know that if you have any issues at all, please feel free to bring them up. For instance, if you have other files (such as a file that lists all books or anything like that), and you cannot get it to work with the new database structure, please do not hesitate to send it to me. I will gladly update that file for you. Just send whatever you need help with.

Thank you again!
Customer: replied 1 year ago.

Did you get my last reply? I don't see it here. Anyway, what I said was I had two other joining tables like you created but I couldn't get my query to work so I thought it might be easier with only the three, so I reworked them the bookID to them.


 


And you were, right, totally messed up my viewBooks.php file and I have uploaded at http://ge.tt/8TSTKde?c

Expert:  TheDoctor replied 1 year ago.
No, I didn't receive your last reply. But now I know.

I will get your viewBooks.php fixed and send it to you soon.

Thank you
Customer: replied 1 year ago.

I did try the editBooks.php code and it didn't work. It may have to do with the pagination and sort code that is on the viewBooks.php

Expert:  TheDoctor replied 1 year ago.
Hello again!

Please download the file here:


That should fix that page for you. Please do not hesitate to ask me any other questions.

If you require assistance in the future, please feel free to request me directly by starting your quesitons with **For TheDoctor**. It would be my pleasure to assist you again.

Please remember to rate my answer. Thank you so much!
Expert:  TheDoctor replied 1 year ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.
TheDoctor, Professional w/Adv. Degree
Category: Homework
Satisfied Customers: 1524
Experience: M.S. in Internet Information Systems
TheDoctor and 2 other Homework Specialists are ready to help you
Customer: replied 1 year ago.

Thanks, XXXXX XXXXX great.


 


I see what you're talking about. I had attempted to add a book earlier, and it looks like it added the book information but did not add the author or publisher information to the other two tables. I'll delete that book manually from the database.

Expert:  TheDoctor replied 1 year ago.
Excellent! If you need anything else, just let me know!

Have a great night.
Customer: replied 1 year ago.

You too. I actually have music and movies to do the same way, and now I need to go back and re-add the tables I deleted for those. Luckily I have an old copy of those somewhere.

Expert:  TheDoctor replied 1 year ago.
Remember to add the unique key to the name on the movies or music. See how I did that in the SQL for the other two? I added UNIQUE to authName and pubName.

That way, when an insert is attempted, the unique key will actually trigger the "ON DUPLICATE KEY UPDATE" part. Without the unique key, it will not trigger that part.
Customer: replied 1 year ago.

I will. Thank you again. I've been working on these for weeks, while also working on other files on the page.

Expert:  TheDoctor replied 1 year ago.
You are very welcome.

JustAnswer in the News:

 
 
 
Ask-a-doc Web sites: If you've got a quick question, you can try to get an answer from sites that say they have various specialists on hand to give quick answers... Justanswer.com.
JustAnswer.com...has seen a spike since October in legal questions from readers about layoffs, unemployment and severance.
Web sites like justanswer.com/legal
...leave nothing to chance.
Traffic on JustAnswer rose 14 percent...and had nearly 400,000 page views in 30 days...inquiries related to stress, high blood pressure, drinking and heart pain jumped 33 percent.
Tory Johnson, GMA Workplace Contributor, discusses work-from-home jobs, such as JustAnswer in which verified Experts answer people’s questions.
I will tell you that...the things you have to go through to be an Expert are quite rigorous.
 
 
 

What Customers are Saying:

 
 
 
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
< Last | Next >
  • Wonderful service, prompt, efficient, and accurate. Couldn't have asked for more. I cannot thank you enough for your help. Mary C. Freshfield, Liverpool, UK
  • This expert is wonderful. They truly know what they are talking about, and they actually care about you. They really helped put my nerves at ease. Thank you so much!!!! Alex Los Angeles, CA
  • Thank you for all your help. It is nice to know that this service is here for people like myself, who need answers fast and are not sure who to consult. GP Hesperia, CA
  • I couldn't be more satisfied! This is the site I will always come to when I need a second opinion. Justin Kernersville, NC
  • Just let me say that this encounter has been entirely professional and most helpful. I liked that I could ask additional questions and get answered in a very short turn around. Esther Woodstock, NY
  • Thank you so much for taking your time and knowledge to support my concerns. Not only did you answer my questions, you even took it a step further with replying with more pertinent information I needed to know. Robin Elkton, Maryland
  • He answered my question promptly and gave me accurate, detailed information. If all of your experts are half as good, you have a great thing going here. Diane Dallas, TX
 
 
 

Meet The Experts:

 
 
 
  • Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4522
    More than 5000 online tutoring sessions.
< Last | Next >
  • http://ww2.justanswer.com/uploads/BU/BusinessTutor/2012-2-2_115741_Kouki2.64x64.jpg Manal Elkhoshkhany's Avatar

    Manal Elkhoshkhany

    Tutor

    Satisfied Customers:

    4522
    More than 5000 online tutoring sessions.
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3458
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/LI/lindaus/2012-6-10_04811_IMG20120609164157.64x64.jpg Linda_us's Avatar

    Linda_us

    Finance, Accounts & Homework Tutor

    Satisfied Customers:

    3124
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/chooser77/2009-08-18_162025_Chris.jpg Chris M.'s Avatar

    Chris M.

    M.S.W. Social Work

    Satisfied Customers:

    2385
    Master's Degree, strong math and writing skills, experience in one-on-one tutoring (college English)
  • http://ww2.justanswer.com/uploads/JawaadAhmed/2009-6-27_12137_SIs_SHadi.jpg F. Naz's Avatar

    F. Naz

    Chartered Accountant

    Satisfied Customers:

    1988
    Experience with chartered accountancy
  • http://ww2.justanswer.com/uploads/JK/jkcpa/2011-1-16_182614_jkcpa.64x64.jpg Bizhelp's Avatar

    Bizhelp

    CPA

    Satisfied Customers:

    1876
    Bachelors Degree and CPA with Accounting work experience
  • http://ww2.justanswer.com/uploads/avremote/photoa.jpg Seanna's Avatar

    Seanna

    Tutor

    Satisfied Customers:

    1781
    3,000+ satisfied customers, all topics, A+ work
 
 
 

Related Homework Questions