skip to Main Content

I made a simple register page, but when I click on the register button, it is not adding the specified values in the myphpadmin database which i am using , instead displaying my whole php code in the browser.

This is my insertit.php code.

<?php

$name = $_post['name'];
$password = $_POST['password'];
$collegename = $_POST['collegename'];
$mobilenumber = $_post['mobilenumber'];
$emailid = $_post['emailid'];
$gender = $_post['gender'];
$category = $_post['storemp'];

if (!empty($name) || !empty($password) || !empty($collegename) ||
!empty($mobilenumber) ||
!empty($emailid) || !empty($gender) || !empty($category)) {
    $host = "localhost";
    $dbUsername = "root";
    $dbPassword = "";
    $dbname = "onlinequiz";

    $conn = new mysqli($host, $dbUsername, $dbPassword, $dbname);

    if (mysqli_connect_error()) {
        die('Connect error('.mysqli_connect_errno().')'.mysqli_connect_error());
    } else {
        $SELECT = "SELECT email From register Where email= ? Limit 1";
        $INSERT = "INSERT Into register (name, password,collegename, 
            mobilenumber,emailid, gender, category) values 
            (?,?,?,?,?,?,?)";

        $stmt = $conn->prepare($SELECT);
        $stmt->bind_param("s", $email);
        $stmt->execute();
        $stmt->bind_result($email);
        $stmt->store_result();

        if ($stmt->num_rows == 0) {
            $stmt->close();

            $stmt = $conn->prepare($INSERT);
            $stmt->bind_param("sssisss", $name, $password, $collegename, $mobilenumber, $emailid, $gender, $category);
            $stmt->execute();
            echo "Registration Successful";
        } else {
            echo "Someone already registered using this email";
        }

        $stmt->close();
        $conn->close();
    }
} else {
    echo "All field are required";
    die();
}
?>

and this is my register page code.

<html>
<style>
div
{
width:400px;
height:500px;
background color:green;
}
body
{
background-image:url("userregistration.jpg");
height:100%;
background-position:center;
}
</style>
<body>
<form action="insertit.php" method="POST">
<center><div><marquee><h1> USER REGISTRATION !! </h1></marquee> 
<hr>
<fieldset>
<legend> <b>USER DETAILS </b></legend>
<ul type="square">
<li>Name: <input type="varchar" name="name" required></li><br><br>
<li>Password: <input type="varchar" name="password" required></li><br> <br>
<li>college name: <input type="varchar" name="collegename" required></li><br><br>
<li>mobile number:  <input type="varchar" name="mobilenumber" required> </li><br><br>
<li>email address: <input type="email" name="emailid" required></li> <br><br>

gender: <input type="radio" name="gender" value="m" required>male
      <input type="radio" name="gender" value="f" required>female<br><br>
student or employee: <input type="radio" name="storemp" value="student" required>student
      <input type="radio" name="storemp" value="employee" required>employee <br>
<input type="submit">
</ul>
</fieldset></div></center>
</form>

</body>
</html>

Now, when I click on the register button, it opens up the php code in the browser.
I am using phpmyadmin and xampp to operate.

Note: My localhost database connection shows unsecured. I thought that might be a problem. In case if it is do let me know the solution. I am attaching a screen snip of the same.
Screen snip of unsecured connection through xampp

Can anyone help me out with this simple problem.

2

Answers


  1. Try type=”text” instead of type=”varchar”

    Login or Signup to reply.
  2. If your PHP code is being shown in the browser, it implies that your server has not been setup to serve PHP scripts.
    Below are among few things you will need to do.

    1.)First step is to ensure that PHP is installed and running correctly. This may sound hey hey, but who knows. An easy way to check is to run php -v from a command line and see if returns version information or any errors

    2.) Restarting your Server: If you have alter any files prior to this event, you will need to restart your server

    3.) PHP File Extension Name Ensure that you properly save your code as .php file extension name. Code save as .html or .txt will not be executable.

    4.) Ensure that your php files resides on htdocs folder if you are using xampp Eg

    C:xampphtdocsyour-php-projects.
    

    5.)Misconfiguration: This may be the last thing to check. But if you care about it, You can also check for misconfigurations.

    For example: In Apache’s httpd.conf file,
    you will need to make sure that the line Eg as case may be “LoadModule php5_module
    has been uncommented and that there is no semi-colon (;) at the beginning of the line.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search