Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HTML not being loaded in PHP Document

Tags:

html

php

I am writing a basic PHP login/Registration script and for some reason as soon as I add a PHP command the HTML isn't loaded. I had a look at the source but there is nothing loaded at all. I am hoping I have missed something very basic, but I am also having a couple of teething issues with the version of PHP installed on the web server.

<?php
 require_once('connect.php');
 if(isset($_POST) & !empty($_POST)){
    $username = mysql_real_escape_string($_POST['username']);
    $email = mysql_real_escape_string($_POST['email']);
    $password =md5($_POST['password']);

    $sql = "INSERT INTO 'login' (username, email, password) VALUES ('$username, $email, $password)";
    $result = mysql_query($connection, $sql);
    if($result){
        echo "User Rego Secusseflllgk";
    }else{
        echo "User rego faile";
    }
}
?>


<!DOCTYPE html>

<html>
<head>
    <title>USer Reg in PHP & MySQL</title>  
</head>
<center>
<body>
    <div class="container">
            <form class="form-signin" method="POST">
            <h2 class="form-sigin-heading">Please register</h2>
        <div class="input-group">
            <span class="input-group-addon" id="basic-addon1">@</span>
            <input type="test" name="username" class="form-control" placeholder="Username" required>
        </div>
            <label for="inputEmail" class="sr-only">Password</label>
            <input type="email" name="email" id="inputEmail" class="form-control" placeholder="Email address" required autofocus>
            <label for="inputPassword" class="sr-only">Password</label>
            <input type="password" name="password" id="inputPassword" class="form-control" placeholder="Password" required>
            <button class="btn btn-lg btn-primary btn-block" type="submit">Register</button>
            <a class="btn btn-lg btn-primary btn-block" href="login.php">Login</a>
        </form>
    </div>
</body>
</html>

I tried to print the POST request but this didnt shed any light on the issue

print_r($_POST);
like image 618
Zach Newton Avatar asked Mar 20 '26 11:03

Zach Newton


1 Answers

You are using deprecated functions and your if-statement is incorrect.

Use if(isset($_POST) && !empty($_POST)){

The mysql_query should be mysqli_query, the function you use:

http://php.net/manual/en/function.mysql-query.php

mixed mysql_query ( string $query [, resource $link_identifier = NULL ] )

VS the new one:

http://php.net/manual/en/mysqli.query.php

mixed mysqli_query ( mysqli $link , string $query [, int $resultmode = MYSQLI_STORE_RESULT ] )

You are placing the connection first, and than the Query, which doesn't work for mysql_query. In mysqli_query that mark-up does work.

like image 121
Hespen Avatar answered Mar 23 '26 02:03

Hespen