Jump to content

Question


idkwhy

Recommended Posts

Hi! I'm new. I'm Gabby.  :3

 

I'm currently self teaching myself php, MySQL, and Ajax for a simulation game I'm opening up where you can breed, show, and train dogs. :)

 

I've been reading tutorials on how to create a sign up page with a confirmation email being sent to you. However, I don't understand why I need multiple pages. For instance, with the tutorial I learned, you have to create three pages. One to configure and connect your site to the DB, one to display the form to sign up with, and one to display a success/failed message. My issue with that is I know it's possible using php (or is it Ajax?) to have one page. An example is on http://dogdayzz.com, when you sign up the page doesn't redirect you anywhere, it uses the same php file the entire time. Is this because the code for the form is printed in an if statement, then cleared and executed with an error/success prompt?

 

Hopefully someone can help me out.. I couldn't find anything on google. :/

Thanks everyone for your time

 

Gabby

Link to comment
Share on other sites

An example is on http://dogdayzz.com, when you sign up the page doesn't redirect you anywhere, it uses the same php file the entire time. Is this because the code for the form is printed in an if statement, then cleared and executed with an error/success prompt?

I think you are mixing up the concept of pages and scripts. For example, you say the tutorial said you would need a separate "page" for the database connection. Well, a user would not navigate to a URL to do that. It is all handled int he PHP code. For the purposes of clean/efficient code you want to break down the functionality into separate scripts (files) that do specific tasks. If you have a site that is going to be interacting with the database a lot you don't want to write your database connection routine on every single "page". instead you create the script once and include() it on the pages you need it. A simple login "page" can use many different files/scripts.

 

I suggest you read those tutorials a little more in-depth and actually try to understand the flow of the logic. Here is a rogh exampl of a possible login "page":

<?php
]//Check if form was posted
if($_SERVER['REQUEST_METHOD'=='POST')
{
    //Insert code to validate the posted data

   if($valid)
    {
        include('form_processing_script.php');
        include('confirmation_message.php');
        exit();
    }
    else
    {
        //Create error message to show in form
    }
}
include('form_script.php');
?>

Link to comment
Share on other sites

That's because the form is submitting back upon itself (to the same page).

 

To accomplish this use the name of the file in the form action like so:

 


<form action ="same_page_of_form.php" Method="POST">

 

When the user submits the form, it will simply submit back to same_page_of_form.php. So if your form is on index.php and you want to stay on index.php, simply use index.php in the action.

Link to comment
Share on other sites

Is this because the code for the form is printed in an if statement, then cleared and executed with an error/success prompt?

 

It is very likely that is how they have it.  Although, there are multiple ways you can do it.

 

1. AJAX, this method will submit data to the server without reloading the page.

2. PHP is able to send the data to a second page, check it, then re-direct back to the main page, behind the scenes.

3. PHP can also use if/else clauses to do the same affect.

 

 

So there is not 1 defined way of doing anything in PHP.  Although, everyone will have their own opinions of what 'right' is.  However, when thinking of designing anything that relates to databases, and/or a user base, there are fundamentals that must be addressed.

 

1. security

  a. user information protection.

  b. site protection.

2. data

  a. integrity

  b. validation.

 

There are other things, but I personally think those are the MOST important.

 

There is one VERY important thing about MySQL that many fail to learn until it causes a full re-write of their code base.  And that is normalization.

, it would be wise to watch these 9 videos.
Link to comment
Share on other sites

An example is on http://dogdayzz.com, when you sign up the page doesn't redirect you anywhere, it uses the same php file the entire time. Is this because the code for the form is printed in an if statement, then cleared and executed with an error/success prompt?

I think you are mixing up the concept of pages and scripts. For example, you say the tutorial said you would need a separate "page" for the database connection. Well, a user would not navigate to a URL to do that. It is all handled int he PHP code. For the purposes of clean/efficient code you want to break down the functionality into separate scripts (files) that do specific tasks. If you have a site that is going to be interacting with the database a lot you don't want to write your database connection routine on every single "page". instead you create the script once and include() it on the pages you need it. A simple login "page" can use many different files/scripts.

 

I suggest you read those tutorials a little more in-depth and actually try to understand the flow of the logic. Here is a rogh exampl of a possible login "page":

<?php
]//Check if form was posted
if($_SERVER['REQUEST_METHOD'=='POST')
{
    //Insert code to validate the posted data

   if($valid)
    {
        include('form_processing_script.php');
        include('confirmation_message.php');
        exit();
    }
    else
    {
        //Create error message to show in form
    }
}
include('form_script.php');
?>

This here: http://phpeasystep.com/phptu/24.html was the tutorial I read. I did thoroughly read through it, but as you can see, it's very simple and vague

 

I appreciate what you told me about the include. I did actually know that, and in the tutorial it follows the include code. However my issue is that once you complete the form it redirects you to a separate file ("signup_ac.php") where it says if your confirmation was sent successfully. That's my issue because I know it's possible to eliminate that extra step and have it so the prompt replaces the form on the original sign up page.

 

Is that a little clearer? I apologize

 

--

 

 

That's because the form is submitting back upon itself (to the same page).

 

To accomplish this use the name of the file in the form action like so:

 


<form action ="same_page_of_form.php" Method="POST">

 

When the user submits the form, it will simply submit back to same_page_of_form.php. So if your form is on index.php and you want to stay on index.php, simply use index.php in the action.

 

That's actually what I thought was how to fix it. I'll try that and get back to you. Thank you!

 

--

 

Is this because the code for the form is printed in an if statement, then cleared and executed with an error/success prompt?

 

It is very likely that is how they have it.  Although, there are multiple ways you can do it.

 

1. AJAX, this method will submit data to the server without reloading the page.

2. PHP is able to send the data to a second page, check it, then re-direct back to the main page, behind the scenes.

3. PHP can also use if/else clauses to do the same affect.

 

 

So there is not 1 defined way of doing anything in PHP.  Although, everyone will have their own opinions of what 'right' is.  However, when thinking of designing anything that relates to databases, and/or a user base, there are fundamentals that must be addressed.

 

1. security

  a. user information protection.

  b. site protection.

2. data

  a. integrity

  b. validation.

 

There are other things, but I personally think those are the MOST important.

 

There is one VERY important thing about MySQL that many fail to learn until it causes a full re-write of their code base.  And that is normalization.

, it would be wise to watch these 9 videos.

 

I like choice two and three the best. And I do agree with everything you said regarding security and data.

 

Andd I'll watch those videos soon

Link to comment
Share on other sites

Thank you!!!! So much!!! I had a feeling they were outdated but being a total newb, I would have went and used them stupidly.

 

Is it possible you can provide me with some learning sources which in your opinion are better and more up to date?

 

Thank you soo much!!

Link to comment
Share on other sites

I appreciate what you told me about the include. I did actually know that, and in the tutorial it follows the include code. However my issue is that once you complete the form it redirects you to a separate file ("signup_ac.php") where it says if your confirmation was sent successfully. That's my issue because I know it's possible to eliminate that extra step and have it so the prompt replaces the form on the original sign up page.

 

Is that a little clearer? I apologize

There are 101 ways to build the functionality for a form. You can have everything update on the page without an actual page refresh using AJAX. But, that is something you should implement AFTER you have a fully working page without AJAX. Also, a good reason why you would want to redirect the user after a successful form submission is that it will clear the POST data. Otherwise you have to handle the situation of users clicking the refresh button and preventing duplicate entries. A redirect is an easy way yo prevent this.

Link to comment
Share on other sites

Thank you!!!! So much!!! I had a feeling they were outdated but being a total newb, I would have went and used them stupidly.

 

Is it possible you can provide me with some learning sources which in your opinion are better and more up to date?

 

Thank you soo much!!

 

Yeah, Pikachu2000 hit the nail on the head with the manual reference and you need to bookmark that site. Though, sometimes it can be confusing for those just learning PHP IMHO.

 

If you like books, one of my favorites is Beginning PHP and MySQL and if you're more of a visual type of learner through "live video" teaching, http://thenewboston.org/tutorials.php has awesome tutorials on quite a few languages, including PHP (It's under the Computer Programming) section on that page.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.