I've been trying to make a registration page and a login page but it's not working. :'(

Please help.

Dani AI

Generated

A short, practical checklist and minimal examples to resolve the usual PHP registration/login failures mentioned by and prompted by , and . The most common problems are simple: form inputs without name attributes, wrong form method/action, broken DB connection, unhashed passwords, and missing session handling. The steps below are focused troubleshooting and secure patterns that work for modern PHP.

  • HTML/form: use method="post", set action correctly, and ensure every input has a name.
  • Server-side: check $_SERVER['REQUEST_METHOD'] === 'POST' and isset()/!empty() for expected $_POST keys.
  • DB: verify host/user/password/dbname and that PDO or mysqli is installed; test connection separately.
  • Queries: always use prepared statements (PDO or mysqli) — never interpolate raw input into SQL.
  • Passwords: store only hashes produced by password_hash() and validate with password_verify().
  • Sessions: call session_start() before any output; call session_regenerate_id(true) after successful login.
  • Debugging: temporarily enable ini_set('display_errors',1); error_reporting(E_ALL); and check server error logs; revert display_errors in production.
  • Common gotchas: mismatched input name vs. $_POST key, using GET, wrong table/column names, or header redirects after output.

Minimal server-side patterns (examples):

<?php
// register.php
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
    $pdo = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4','dbuser','dbpass', [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);
    $hash = password_hash($_POST['password'], PASSWORD_DEFAULT);
    $stmt = $pdo->prepare('INSERT INTO users (username,email,password_hash,created_at) VALUES (?,?,?,NOW())');
    $stmt->execute([$_POST['username'], $_POST['email'], $hash]);
}
?>
<?php
// login.php
session_start();
$pdo = new PDO('mysql:host=localhost;dbname=yourdb;charset=utf8mb4','dbuser','dbpass', [
    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
]);
$stmt = $pdo->prepare('SELECT id,password_hash FROM users WHERE username = ? LIMIT 1');
$stmt->execute([$_POST['username']]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if ($user && password_verify($_POST['password'], $user['password_hash'])) {
    session_regenerate_id(true);
    $_SESSION['user_id'] = $user['id'];
}
?>

Notes and cautions: do not leave display_errors enabled in production; run over HTTPS; add CSRF tokens on forms; rate-limit failed logins; and never store plain-text passwords. For debugging, compare actual HTML name attributes with the $_POST keys the server-side script expects and confirm the prepared statement executes without throwing exceptions.

Recommended Answers

All 5 Replies

Please specify the language which you are using. If you are using open scripts then you can download these scripts from Google or any other search engine

For registration you need database to store registered users, do you have one?

The language I'm using is php and html.

Yes, I have a database. Its called phpMyAdmin.

Are you getting any errors?

Post some of your codes that you thought it is not working.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.