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: 1403
Experience:  M.S. in Internet Information Systems
Type Your Homework Question Here...
TheDoctor is online now
A new question is answered every 9 seconds

I need some help fixing my php login code.

Resolved Question:

I need some help fixing my php login code.
Submitted: 8 months ago.
Category: Homework
Expert:  TheDoctor replied 8 months ago.
Hello and thank you for your question. Is this for an assignment or course work? It is alright if it is.

Please send me the code that you have. Also, you can export your database from PHPMyAdmin. Take all of the files and zip them up. Then upload the zip file 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.

Thank you
Customer: replied 8 months ago.

Heres the gett link: http://ge.tt/4J1An7y/v/0?c


 


Also, here is an example page of how the log on is supposed to work. I also need help with the delete function and the log out button.


 


http://web.engr.oregonstate.edu/~sagalynr/php_example/index.php

Expert:  TheDoctor replied 8 months ago.
Thank you. I will review your files and get back to you soon.
Customer: replied 8 months ago.

Obviously this is for a school assignment. Can you explain what you are doing? Maybe online?


 

Expert:  TheDoctor replied 8 months ago.
Yes.

Once I have had a chance to fully review your code, I will provide a detailed explanation for you.
Customer: replied 8 months ago.

Thx


 

Expert:  TheDoctor replied 8 months ago.
Hello again!

Please download the files here:

DOWNLOAD

The login.php file contains the changes.

And here is the explanation:

First, you where checking if $_POST was set. It is better to do $_SERVER['REQUEST_METHOD'] == 'POST'

Next, you did not have all of your code for processing on post inside of that conditional. That was just a simple mistake and it resulted in a couple warnings if your PHP is set up to display warnings. I fixed that for you.

If you are running queries with passed-in data from a form, you should use prepared statements, as it automatically escapes the data. You were doing this one one of the queries but not the others.

If you look at the new code line by line, you can easily see what is being done. Your code was almost there and pretty good, so you obviously have a good understanding of this stuff.

First, we run a query to look for a password XXXXX on the entered username.

That is on line 21. We set the returned password XXXXX the $result variable. If the passed-in password XXXXX the form is equal to the result, then we redirect the user to the todo page and exit. If you do not exit, the page will technically continue to be processed by the server even after it has redirected the user. So it is best practice to always exit after a header redirect. You were having a link display for the user to click and go to the todo page after successful log in. However, you can simply redirect the user to the todo page, as I have done here.

Next, if the password XXXXX not match but there IS a password XXXXX then the user typed in a username that exists in the database but the incorrect password. The page sets a variable for a user message to tell the user that it is the Incorrect Login. This is displayed on the page.

Then there is another else... this time it means that $result is empty. That means that the user name does not exist in the database. So it goes ahead and inserts it in the exact same way that your code was doing. But now, it also creates a message to let the user know that a new user has been created and is displayed on the page.

I think that covers everything that is going on in the script. If you have any questions at all about any of the code, just let me know and I will explain it. I'm here to help!

If you require assistance in the future, please feel free to request me directly by starting your question with **For TheDoctor**.

Please remember to rate my answer. Thank you so much and have a wonderful day!
Customer: replied 8 months ago.

Want to fix a couple other issues? I'll rate you as excellent as you did exactly what I need. But I have 3 other things I can't get to work-



  • I need a delete button on each todo list item that removes it from the database and from the screen. (see the example site)



  • I need a log out button in the upper right corner

  • I need the session variables to work so that a person can't get to the ToDo page unless they log in.


 


How much to fix these things?

Expert:  TheDoctor replied 8 months ago.
Hello again!

I'll make these edits for you. Once they are complete and you provide a positive rating, you can leave a bonus of however much you want to leave.

I will contact you once these additional changes are ready.

Thank you
Customer: replied 8 months ago.

The link in the original package has an example of what its supposed to do if that helps.


Thank you. Can I ask questions about what you've done after I get a chance to look at the code?


 

Expert:  TheDoctor replied 8 months ago.
Hello again,

Yes, you can ask questions.

The example link that you gave me goes to a page that allows you to enter a string, a substring, and then remove part of the string. It doesn't have anything related to logins or todo lists.
Customer: replied 8 months ago.

http://web.engr.oregonstate.edu/~sagalynr/login/index.php


 


Actually, this one doesn't have the todo page working. But I think mine is close. Its supposed to have a delete link next to each listed todo item below the input box. That link deletes the todo item from the db and from the page.


 


Thanks.


 

Expert:  TheDoctor replied 8 months ago.
Tell me a little more about the todo items, as it may require a database change?

Can a user have more than 3 todo items? If so, your database currently violates 1st Normal Form and will need a slight change. I can easily do that, just let me know about these todo items.

Thank you
Customer: replied 8 months ago.

I don't mind if it violates that rule- I'm aware I should use a second databse for the todo items, but its not critical. I'll let you be the judge. I do understand about primary keys and foreign keys.


A user can have more that 3 items, but I need to make sure I understand how you do that- I sure couldn't do that now.


 


Thanks. Again.


Wayne

Customer: replied 8 months ago.

If I want to remove the ability to add a new user (register) how will I do that? The actual assignment doesn't require that. I can just check against two preloaded users, test 1/ password XXXXX and test 2/password XXXXX


 


Thanks

Expert:  TheDoctor replied 8 months ago.
I'll remove it along with these other changes and let you know what I did. Thank you.
Expert:  TheDoctor replied 8 months 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: 1403
Experience: M.S. in Internet Information Systems
TheDoctor and 2 other Homework Specialists are ready to help you

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:

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

    4520
    More than 5000 online tutoring sessions.
  • 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:

    3121
    Post Graduate Diploma in Management (MBA)
  • http://ww2.justanswer.com/uploads/ComputersGuru/2010-02-13_051118_Photo41.JPG LogicPro's Avatar

    LogicPro

    Engineer

    Satisfied Customers:

    3035
    Expert in Java C++ C C# VB Javascript Design SQL HTML
  • http://ww2.justanswer.com/uploads/lanis/2009-4-1_233717_phput9xef_c1pm.jpg Lani S.'s Avatar

    Lani S.

    Tutor

    Satisfied Customers:

    2457
    Registered Nurse, Internet Researcher, Private Tutor
  • 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:

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

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

    1873
    Bachelors Degree and CPA with Accounting work experience