Help with php

Paul159

Active member
Joined
Mar 20, 2014
Messages
87
Reaction score
0
Can someone explain what's wrong with this code:



<?php include_once("scripts/global.php");
$message = '';
if(isset($_POST['username'])){
       
        $username =$_POST['username'];
        $fname = $_POST['fname'];
        $lname = $_POST['lname'];
        $email = $_POST['email'];
        $pass1 = $_POST['pass1'];
        $pass2 = $_POST['pass2'];
       
        //error handeling
        if((!$username||(!$fname)||(!$lname)||(!$email)||(!$pass1)||(!$pass2)){
                $message = 'Please insert all fields';
        }else{
                if($pass1 != $pass2){
                        $message = 'Your password fields doesnt match';
                }else{
                        //securing the data
                        $username = preg_replace("#[^0-9a-z]#i","",$username);
                        $fname = preg_replace("#[^0-9a-z]#i","",$fname);
                        $lname = preg_replace("#[^0-9a-z]#i","",$lname);
                        $pass1 = sha1($pass1);
                       
                        $email = mysql_real_escape_string($email);
                       
                        //check for dublicates
                        $user_query = mysql_query("SELECT username FROM members WHERE username='$username' LIMIT1") or die("Could not check username");
                        $count_username = mysql_num_rows($user_query);
                       
                        $email_query = mysql_query("SELECT email FROM members WHERE email='$email' LIMIT1") or die("Could not check username");
                        $count_email = mysql_num_rows($email_query);
                       
                        if($count_username > 0){
                                $message = 'This username has been already registered';
                        }else if($count_email > 0){
                                $message = 'This email has been already registered';
                        }else{
                                //insert the members
                                $ip_address = $_SERVER["REMORE_ADDR"];
                                query = mysql_query("INSERT INTO members (username, firstname, lastname, email, password, ip_address, sign_up_date)VALUES("$username","$fname","$lname","$email","$pass1","$ip_address", now())") or die("Could not insert your information");
                                $member_id = mysql_insert_id();
                                mkdir("users/$member_id",0755);
                                $message = "You are now been registered!";
                        }
                       
                }
               
       
        }
       
}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content=
    "text/html; charset=utf-8" />
    <title>
      Register To PrizePTS
    </title>
    <link href="css/global.css" rel="stylesheet" type="text/css" />
  </head>
  <body>
    <div class="container center">
      <h1>
        Register To PrizePTS By Filling The Fields Below
      </h1>
      <p>
        <?php print($"message");?>
      </p>
      <form action="register.php" method="post">
        <input type="text" name="username" placeholder=
        "Username" />

        <input type="text" name="fname" placeholder=
        "Firstname" />

        <input type="text" name="lname" placeholder=
        "Lastname" />

        <input type="text" name="email" placeholder=
        "Email address" />

        <input type="password" name="pass1" placeholder=
        "Password" />

        <input type="password" name="pass2" placeholder=
        "Validate Password" />

        <input type="submit" value="Register" />
      </form>
    </div>
  </body>
</html>
 

Fu$10N

Expert
Joined
Mar 5, 2014
Messages
1,101
Reaction score
8
Hmph, what seems to be the problem ? Not working when opening up the .html ?
 

Paul159

Active member
Joined
Mar 20, 2014
Messages
87
Reaction score
0
Fu$10N link said:
Hmph, what seems to be the problem ? Not working when opening up the .html ?
It should open normal registration form but , all code shows up
 

Furious2

Member
Joined
Aug 1, 2013
Messages
13
Reaction score
0
I'm currently learning PHP, so I'm not a master :p
The reason is PHP files first need be processed in a web server before sending their output to the web browser.
As far as I know before running PHP files, they should be placed inside the web folder of a web server and then make a request to desired PHP file by typing its URL in the web browser.
In other words, you must have XAMPP installed and run Apache, then you put your files at "htdocs" which is under the root directory of XAMPP, to test you open "http://localhost/" you can run that file with "http://localhost/yourfilename.php"
 

Paul159

Active member
Joined
Mar 20, 2014
Messages
87
Reaction score
0
Furious2 link said:
I'm currently learning PHP, so I'm not a master :p
The reason is PHP files first need be processed in a web server before sending their output to the web browser.
As far as I know before running PHP files, they should be placed inside the web folder of a web server and then make a request to desired PHP file by typing its URL in the web browser.
In other words, you must have XAMPP installed and run Apache, then you put your files at "htdocs" which is under the root directory of XAMPP, to test you open "http://localhost/" you can run that file with "http://localhost/yourfilename.php"
I can just drag file into browser , it doesn't solve my problem
 
Top