<?php
$firstname = $_POST{'firstname'};
$username = $_POST{'username'};
$emailaddress = $_POST{'emailaddress'};
$password = $_POST{'password'};
$contact = $_POST{'contact'};

//Database connection
$conn =new mysqli('localhost','root','','registration');
if ($conn->connect_error) {
    die('connection failed : '.$conn->connect_error)
}else{
    $stmt = $conn->prepare("insert into users(firstname, username, emailaddress, password, contact)
        vlaues (?, ?, ?, ?, ?)")
    $stmt-> bind param("ssssi",$firstname, $username, $emailaddress, $password, $contact)
    $stmt->execute();
    echo "Submitted Succesfully...";
    $stmt->close();
    $stmt->close();
}

?>

Benjamin_17 commented: Not sure if it a copy and paste error but line 15 should be bind_param not bind param. +0

Dani AI

Generated

Quick note for and thanks to for the catch — a parse error like "unexpected 'if' (T_IF)" usually means PHP found an if where it expected the previous statement to end. That points to a syntax problem earlier in the file: a missing semicolon, an unclosed quote/parenthesis/brace, or a stray token. Start by checking the line number the error mentions and then scan the lines immediately above it.

Turn on full error reporting and make mysqli raise exceptions so errors show exact locations. Add this near the top of the script:

<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);

See the PHP docs on error_reporting and mysqli prepared statements for details.

Other things to verify before re-running: every PHP statement ends with ;; all quotes and parentheses are closed; SQL keywords are spelled correctly; bind_param types match your variables; you call close() only once per statement; and do not store plain-text passwords (use password_hash). If the error persists, post the full error message and the complete PHP file (or the few lines around the reported line) and someone can point to the exact offending token.

You don't have a semi-colon at the end of lines 11, 14, and 15.

However, to fully diagnose this, please post the full PHP file as well as the full error message. The error mesage should specify what line the error is on.

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.