0

I am using wamp server and trying to create simple sign up page with html forms and php script; but the problem is whenever I am hitting on submit button on html page, it is directly showing the entire content of php file in next browser instead of executing the php file.

the following is my form code(index.php)

  <form id="login" action="register.php" method="post">
            <p>
                <label for="first name" >First Name</label>
                <input type="text" name="fname" value=""  />
            </p>
            <p>
                <label for="last name" >Last Name</label>
                <input type="text" name="lname" value="" class="radius2" />
            </p>

            <p>
                <label for="gender" >Gender</label>
                <input type="text" name="gender" />
            </p>
            <p>
                <label for="username" >Email</label>
                <input type="text" name="username" />
            </p>
            <p>
                <label for="password" >Password</label>
                <input type="password" name="password" />
            </p>
            <p>
                <input type="submit" name="submit">Login</input>
            </p>
      </form>

the following is my php code

      $bd = mysqli_connect("localhost", "root","yash1991","shaunak") or die("Could not connect       database");
     echo" hello1";
    mysqli_query($bd,"INSERT INTO users (fname, lname, gender, email_id, username, password)                  VALUES ("$fname", "$lname", "$gender", "$username", "$password")");
     mysqli_close($bd);
    ?>
Yash
  • 246
  • 2
  • 3
  • 20
  • php session_start(); $fname=$_post['fname']; $lname=$_post['lname']; $gender=$_post['gender']; $username=$_post['username']; $password = $_post['password']; These are the starting lines of php code, I dnt know why it didn't get display in my question – Yash Dec 06 '14 at 20:01
  • Is there space between `````` and ```php```? check this post out http://stackoverflow.com/questions/5121495/php-code-is-not-being-executed-i-can-see-it-on-source-code-of-page – Konstantin Dec 06 '14 at 21:34

1 Answers1

0
  1. I suppose that you running WAMP server, and stored your files (index.php & register.php) in folder inside "C:\wamp\www\" and you access your index page using url "127.0.0.1/stack/index.php"
  2. Check your index.php file with the following code:

    <form id="login" action="register.php" method="post">
            <p>
                <label for="First Name">First Name</label>
                <input type="text" name="fname" value="" />                       
            </p>
            <p>
                <label for="last Name">Last Name</label>
                <input type="text" name="lname" value="" class="radius2" />
            </p>        
            <p>
                <label for="gender">Gender</label>
                <input type="text" name="gender" />                       
            </p>        
            <p>
                <label for="username">Email</label>
                <input type="text" name="username" />                       
            </p>        
            <p>
                <label for="password">Password</label>
                <input type="password" name="password" />                       
            </p>                
            <p>
             <input type="submit" name="submit" value="Login" />
            </p>
        </form>
    
  3. Check your register.php file with the following code:

    <?php
    session_start();
    $fname=$_POST['fname'];
    $lname=$_POST['lname'];
    $gender=$_POST['gender'];
    $username=$_POST['username'];
    $password=$_POST['password'];
    
    echo "hello ";
    
    $bd= mysqli_connect("localhost","root","yash1991","shaunak") or die ("Could not connect DB");
    
    $try = mysqli_query($bd, "INSERT INTO users (`fname`, `lname`, `gender`, `email_id`, `password`) VALUES ('$fname', '$lname', '$gender', '$username', '$password')");
    
    if($try === false)
        {
            echo '<br />error - ';
            echo mysqli_error($bd); 
        } else {
            echo '<br />all good';      
         }
    mysqli_close($bd);
    
    ?>
    
ciwmcit
  • 157
  • 1
  • 2
  • My problem got solved; my wampserver's port number was being used by some other process that's why it was treating everything as HTML page and was showing entire content of the file on browser. – Yash Dec 07 '14 at 18:12