Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6943269
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T13:08:00+00:00 2026-05-27T13:08:00+00:00

I’m trying to create a pretty standard user creation form for a website I’m

  • 0

I’m trying to create a pretty standard user creation form for a website I’m working on, but my PHP amateur status is preventing me from accomplishing my goal.

Essentially what I want to do is have the user fill out a registration form, and then have a server-side script attempt to register that information. If the registration succeeds, then the user will be redirected to a page telling them to look for a verification email. If that registration fails (the email address is already in the system, not matching passwords, whatever), I would like to reload the page, but display the error message to the user above the form. Currently the form I have is being echoed out of a php file which is separate from the HTML from where the page is stored. My three questions are this.

  1. From what I’ve read, the way to redirect users on success is to use header(“Location: http://foo.com“). Is that correct, or is there a more proper way to do it?

  2. How can I get access to the error(s) that caused the first user to fail? I’ve read that setting a session variable is a poor idea for a number of different reasons, but without that how can I keep track of the errors thrown by the form validation? Should I just create a global $errors variable that I clear every time I echo the registration form?

  3. For this case, should the page that the registration form is on have a .html extension or a .php extension, or does it not matter? More generally, is there any rule for when a page is .html vs .php/.asp/something else?

Edit: added code below. Note, the form is rendered from a file called in ../views/register_form.php (I assume this is how I’d work on getting something MVC-like in PHP)

The page that the form is rendered on (called index.html)

<body> 
<script type="text/javascript"> <!-- put the jquery load stuff into here -->
$(function(){
  $("#registration_form").load("views/register_form.php");});
</script>


<div class="topbar"><!-- Create the top bar layout-->
  <div class="fill">
    <div class="container">
     <a class="brand" href="#">Website!</a>
     <ul class="nav">
       <li class="active"><a href="#">Home</a></li>
       <li> <a href="#about">About</a></li>
     </ul>
     <form action="scripts/login_user.php" method="post" class="pull-right">
       <input class="input-medium" id="login-email" type="text" name="email_addr"     placeholder="email" />
   <input class="input-medium" id="login-password" type="password" name="password" placeholder="password" />
   <button class="btn" type="submit">Login now!</button>
     </form>
    </div>
  </div>
</div>
<div class="container">
  <div class="content">
    <div class="page header">
     Page header!
    </div>
    <div id="registration_form">
</div>

The script

    if(//some of the data in the form isn't set)
         {
           //Set error conditions based on missing data
         }

    $confirm_password=$_REQUEST['confirm_password'];
    $password=$_REQUEST['password'];
    if($confirm_password != $password){
       //report passwords don't match}


    $email_addr=$_REQUEST['email_addr'];
    $first_name=$_REQUEST['first_name'];
    $last_name=$_REQUEST['last_name'];


try
{
    $successful_creation=create_user_and_send_verification_email($email_addr, $password, $first_name, $last_name);
}
catch(Exception $e)
{
    /*SQL errors are caught here*/
}

if($successful_creation==FALSE)
{
    //If it couldn't be inserted for a non exception generating reason.  If I get here, should I echo a page that has those errors printed, but is otherwise identical to the previous one?
}
else
{
    //redirect to a "wait for a verification email" page
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T13:08:01+00:00Added an answer on May 27, 2026 at 1:08 pm
    1. Yes that is the correct way to do it, but all headers must be sent before you try to render anything to the page. Also, you don’t necessarily need to redirect, you can generate the correct output with PHP depending on the form data.
    2. The script that receives the submitted form should check the submitted data for errors and can then output those errors to the page that is generated by that script.
    3. If the page has php code in it then usually it needs a php extension unless your server is set up to process html pages as php. Otherwise, .html is fine.

    I hope that helps point you in the right direction, although a more focused question with the code you have up to now would generate a better answer.

    There are lots of tutorials on this on the web, you should follow one of those and experiment.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to create an if statement in PHP that prevents a single post
Basically, what I'm trying to create is a page of div tags, each has
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I need to clean up various Word 'smart' characters in user input, including but
I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.