Jump to content

Help making Create/Verify User & Log-In with Heredoc


giefcat

Recommended Posts

I'm trying to make:

 

Create User.

Verify(Make sure its not a copy of the same email, etc..).

Save user to database.

Allow user to login.

 

Using Heredoc and making it one .php is logic while another .php that's included is display/messages. Just really basic, but for some reason I'm having problems.

 

Index:

<html>
<head>
<body>
<a href="create.php">Create Account</a>
<br />
<a href="login.php">Log In</a>
</head>
</body>
</html>

 

create.php

<?php
$here = <<<END
<form action="verify.php" method="post">
   First Name: <input type="text" name="first" /><br />
   Last Name: <input type="text" name="last" /> <br />
   Email: <input type="text" name="email" /> <br />
   Password: <input type="password" name="pass" /><br />
   <input type="submit" value="Submit />
</form>

END;
echo $here
?>

<?php?>

 

verify.php

<?php
include 'verified.php';
   $connection = mysql_connect("localhost", "root", "********");
   if (!$connection) {
      die("Database connection failed: " . mysql_error());
   }
   
   $db_select = mysql_select_db("test", $connection);
   if (!$db_select) {
      die("Database selection failed: " . mysql_error());
   }
   $result = mysql_query("SELECT * FROM users", $connection);
   if (!$result) {
      die("Database query failed: " . mysql_error());
   }
$first = $_POST['first'];
$last = $_POST['last'];
$email = $_POST['email'];
$pass = $_POST['pass'];
$query = "INSERT INTO users (id, first, last, email, pass)
         VALUES (NULL, '{$first}', '{$last}', '{$email}', '{$pass}')";
$create = mysql_query(addslashes($query))
         
              while ($row = mysql_fetch_array($result)) {
               if($row["email"] == $email) {
                    echo "Email in use.";
         } else { if($create) {
            echo "Success!!"; }
         }
      }

mysql_close($connection);
?>

 

and I'm stuck because it won't insert the data into the database. Can anyone help me?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.