Jump to content

Recommended Posts

I have a Create new account page. The form is in page named Register.php and once user submit it, it will go to Confirm.php, where it validates the field if everything is correct shows the " Account Created " Message.

 

In Chrome. The error message is shown in Register.php and once all fields are filled then only will show confirm.php. But in Mozilla, it goes to Confirm.php and shows a blank page.

 

My code for Register.php is :

 

<div class="signup_form">
<form action="confirm.php" method="post" >

<?php 
    session_start();
    if(isset($_SESSION['error']))
    {
        echo '<p>'.$_SESSION['error']['username'].'</p>';
        echo '<p>'.$_SESSION['error']['email'].'</p>';
        echo '<p>'.$_SESSION['error']['password'].'</p>';
        unset($_SESSION['error']);
    }
?>
<p>
<font size="3" face="arial" color="gray"> <label for="username"><b> UserName*</b> </label> </font>
<input name="username" type="text" id="username" input style="height:33px" size = "50" size="30"/>

</p>
<p>
<font size="3" face="arial" color="gray"> <label for="email"><b> E-mail Address*</b> </label> </font>
<input name="email" type="text" id="email"  input style="height:33px" size = "50" size="30"/>
</p>


<p>
<font size="3" face="arial" color="gray"> <label for="password"><b> Password*</b> </label> </font>
<input name="password" type="password" id="password"   input style="height:33px" size = "50" size="30"/>
    </p>  
<p>
<input name="submit" type="image" src="images/submit.gif" value="submit"/>    </p>
</form>

</div>

 

 

and for Confirm.php code is :

 

 

 

<?php
    session_start();
    include('configdb.php');

    if(isset($_POST['submit']))
    {
        if($_POST['username'] == '')
        {

            $_SESSION['error']['username'] = "User Name is required.";
        }
        if($_POST['email'] == '')
        {
            $_SESSION['error']['email'] = "E-mail is required.";
        }
            else
            {
                if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9\._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/", $_POST['email']))
                {
                    $email= $_POST['email'];
                    $sql1 = "SELECT * FROM user WHERE email = '$email'";
                    $result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error($mysqli));
                    if (mysqli_num_rows($result1) > 0) {
                        $_SESSION['error']['email'] = "This Email is already used.";
                    }
                }
                else
                {
                $_SESSION['error']['email'] = "Your email is not valid.";
                }
            }
        if($_POST['password'] == '')
        {
            $_SESSION['error']['password'] = "Password is required.";
        }

        if(isset($_SESSION['error']))
        {
            header("Location: register.php");
            exit;
        }
        else
        {
            $username = $_POST['username'];
            $email = $_POST['email'];
            $password = $_POST['password'];

            $sql2 = "INSERT INTO users (username, email, password) VALUES ('$username', '$email', '$password')";
            $result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());

            if($result2)
            {

            echo '<div>Your account is now active. You may now <a href="login.php">Log in</a></div>';  

Once it reaches the individual browser, it's only HTML, CSS, javascript, etc. that's getting parsed. This probably isn't a PHP problem, but more likely an HTML problem. Look for open tags that aren't closed, especially comment tags, in your View->Source code.

Your browser won't affect your PHP. PHP is run on a server (commonly Apache) as an extension and is executed prior to any information being output to the browser.

 

In other words your problem will be with your client side languages; not server side. The only way PHP will be affected is if the code is run on two different servers with different settings or you adjust the ini settings during run-time... I doubt it though from what you've said and posted.

You are using an image for your submit button. Browsers that follow the w3.org specification (apparently - Chrome, IE, Opera) submit the coordinates where the image was clicked. Other browsers that do their own thing outside of the w3.org specification submit the value = attribute. You can either test for the x or y coordinate, which works in all browsers (see this link - http://us2.php.net/manual/en/faq.html.php#faq.html.form-image ) or you can add a hidden field to your form that submits a specific name/value pair that you can test in your form processing code.

You can either test for the x or y coordinate, which works in all browsers (see this link - http://us2.php.net/manual/en/faq.html.php#faq.html.form-image ) or you can add a hidden field to your form that submits a specific name/value pair that you can test in your form processing code.

 

Additionally, you can just check if $_POST is not empty and assume the request came from your form. You should be double-checking that relevant or necessary data exists and is in the format you expect anyway.

You can either test for the x or y coordinate, which works in all browsers (see this link - http://us2.php.net/manual/en/faq.html.php#faq.html.form-image ) or you can add a hidden field to your form that submits a specific name/value pair that you can test in your form processing code.

 

Additionally, you can just check if $_POST is not empty and assume the request came from your form. You should be double-checking that relevant or necessary data exists and is in the format you expect anyway.

 

Exactly, that was the issue. Image submit button and if(isset($_POST['submit'])) wont match, so I used $_POST instead. Thank you all

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.