-3

Whenever I try to view the site I get an error message. Here is the code:

<?php
 $server = '127.0.0.1';
 $username = 'root';
 $db_name = 'auth';

try{
  $conn = new PDO("mysql:host=$server;dbname=$database;", $username);}
  catch(PDOException $e){
  die( "Connection failed: " . $e->getMessage());
   }

if(!empty($_POST['email']) && !empty($_POST['password'])):

  // enter the new user in the database
  $sql = "INSERT INTO users (email, passowrd) VALUES (;email, :password);
  $stmt = $conn->prepare($sql);

  $stmt->bindParam':email'],_POST['email'];
  $stmt->bindParam((':password',password_hash(POST['password'], PASSWORD_BCRYPT));

  if( $stmt->execute() ):
   die('Success');

  endif;
 endif;

   ?>

I cannot figure out why it is saying that the end bracket for the php code is unexpected.

Hash
  • 4,647
  • 5
  • 21
  • 39
  • 2
    Syntax errors everywhere. `;` instead of `:` on `;email`. Missing `$_`s, missing end quotes to end strings. Missing brackets. – Jonnix Aug 25 '16 at 09:19

1 Answers1

0

There are many syntax errors in your script.

  • In query string ;email should be :email. Also the close double quote is missing

    $sql = "INSERT INTO users (email, passowrd) VALUES (:email, :password)";

                                                      ^^^^               ^^^
    
  • Parenthesis is missing for bindParam. Also $_ is missing before POST

    $stmt->bindParam(':email', $_POST['email']);

                   ^^^                      ^^^^
    
  • Mismatch ( and $_POST issues below the statement:

    $stmt->bindParam(':password', password_hash($_POST['password'], PASSWORD_BCRYPT));

Hope it will be clear to you.

MH2K9
  • 11,951
  • 7
  • 32
  • 49