1

im trying to create a website for a project in school. The first step supposed to be simple - register & login pages. The php code have never worked... (sometimes due to problems in the code and most of the times the result was blank page).

html code:

<!doctype html>
<html>
<title>Tracycle Registration</title>
<link rel="stylesheet" href="test.css">
<div id="header">
<h1>Tracycle</h1>
</div>
<br>
<h3 align="center">Register with your email address</h3>
<br>
<form align="center" action="register.php" method="post">
<input type="email" id="textboxid" placeholder="Email" name="email" size="50" required>
<br><br>
<input type="password" id="textboxid" placeholder="Password" name="password" size="50" required>
<br><br>

<center><input type="submit" name="register" value="Register" ></center>
</form>
</html>

php code:

<?php
$host = "127.0.0.1";
$user = "tracycle";                     
$pass = "";                                 
$db = "users";                          
$port = 3306;                               

$connection = mysqli_connect($host, $user, $pass, $db, $port)or die(mysql_error());

if(isset($_POST['submit']))
{
    $email = $_POST['email'];
    $password = $_POST['password'];

    $check_email = "SELECT * FROM users_information WHERE email='$email"; 

    $run = mysql_query($check_email);

    if(mysql_num_rows($run)>0)
    {
        echo "This email already exists!";
    }

    $query = "INSERT INTO users_information (email, password) VALUES ('$email', '$password')";
    if(mysql_query($query))
    {
        echo "Success!";
    }
}

?>

BTW im using the cloud9 development environment

Do you know what is the problem and why the result is blank page?(after filling the html form and clicking the submit button) I'd love to get help :)

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141
tister20
  • 13
  • 3
  • Activate display errors to trace the source http://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display , it may be a database problem with the connection or the query, the whole code looks fine (but very insecure) – Mariano Montañez Ureta Dec 26 '15 at 18:05

2 Answers2

2
if(isset($_POST['submit']))

Must be

if(isset($_POST['register']))

Try to activate display PHP errors too: How do I get PHP errors to display?

Community
  • 1
  • 1
  • dont know whats he need next, in this case the fix its that, and as an advice i indicated to lear how to activate display errors for the future, there is anything bad with this recommendation? what i should do? thanks @Fred-ii- – Mariano Montañez Ureta Dec 26 '15 at 18:10
1

"php and html register page result is blank page"

A blank page means that you have syntax errors, and there are many errors in your code.

First, your conditional statement for if(isset($_POST['submit'])){...} will never happen, since your submit button has the register name attribute and not submit.

Adding the following to your present code and just before your closing ?> tag, would have echo'd Submit is not set.

else{
   echo "Submit is not set.";
   }

Then you have a missing quote in WHERE email='$email"; which will throw you a syntax error.

You're connecting with the mysqli_ API, but using mysql_ functions.

Those different functions from different MySQL APIs do NOT intermix.

You MUST use the same from connection, to querying.

Consult the following links:

In checking for errors, would have produced quite a few, one of which being an undefined index submit notice.


Your present code is open to SQL injection. Use mysqli_* with prepared statements, or PDO with prepared statements.


Passwords

I also noticed that you may be storing passwords in plain text. This is not recommended.

Use one of the following:

Other links:


HTML stickler.

Your HTML also contains invalid markup.

There should be <head></head> tags with your stylesheet and title declaration inside it and your HTML wrapped in <body></body> tags.

<!doctype html>
<html>
<head>
<title>Tracycle Registration</title>
<link rel="stylesheet" href="test.css">
</head>

<body>
<div id="header">
...
</form>

</body>
</html>
Community
  • 1
  • 1
Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141