3

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);
1
  • Are you using a web service like Apache2? Commented Dec 5, 2016 at 9:29

3 Answers 3

2

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks Hespen, I was also interchanging mysql and msqli in the connection script
You said you were using PHP 7.00, and the mysql functions were all replaced by mysqli at that point! If you were running an older version, you might have gotten away with it. Just remember: When coding in PHP and your page is blank. You've got a PHP error somewhere.
0

Check and review below code,

    <?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($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">Email</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>

Comments

0

use this

if(isset($_POST['email']) && !empty($_POST['email'])){

1 Comment

Currently it's hosted on a net registry server running PHP 7.0. In saying this I have tested 5.3 and 5.6. There are no errors in the error logs and I have tested that $connection actually establishes the connection to the MySQL

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.