Forum Stats

  • 3,783,747 Users
  • 2,254,825 Discussions
  • 7,880,535 Comments

Discussions

Good day, i am still learning mysql and i have developed a simple registration script however when i

4177304
4177304 Member Posts: 1
edited Jan 24, 2020 8:30AM in General Questions

i did research te questions and tried solutions i got however they do not seem to work for me i will post the codes below

<?php

session_start(); //line two

error_reporting(E_ALL);

ini_set('display_errors',1);

$servername = "localhost";

$username = "root";

$password = "";

$dbname = "vuyanii";

$conn = null;

try { //1

    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

    // set the PDO error mode to exception

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    //echo "Connected to DB successfully";

    }

catch(PDOException $e)

    {

    echo $e->getMessage();

    }

global $bcrypt; // making the $bcrypt variable global so we can use here

        $ip = $_SERVER['REMOTE_ADDR'];//getting the ip address of the user

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

            $password_string = $_POST['password'];

            $name = $_POST['name'];

            $surname = $_POST['surname'];

            $ID = $_POST['ID'];

            $phone = $_POST['phone'];

            $email = $_POST['email'];

            $name1 =$_POST['name1'];

            $surname1 = $_POST['surname1'];

            $phone1 = $_POST['phone1'];

            $email1 = $_POST['email1'];

            $relationship = $_POST['relationship'];

            //inserting to the database

            $password_hash = password_hash($password_string, PASSWORD_BCRYPT);

            try{

                $query = "INSERT INTO users(

                    password_hash,name,surname,ID,phone,email,name1,surname1,phone1,email1,relationship) VALUES ($password_string,$name,$surname,$ID,$phone,$email,$name1,$surname1,$phone1,

                        ,$email1,$relationship)";

                $stmt = $conn->prepare($query);

                $stmt->bindparam(":password_string", $password_hash);

                $stmt->bindparam(":name", $name);

                $stmt->bindparam(":surname", $surname);

                $stmt->bindparam(":ID", $ID);

                $stmt->bindparam(":phone", $phone);

                $stmt->bindparam(":email", $email);

                $stmt->bindparam(":name1", $name1);

                $stmt->bindparam(":surname1", $surname1);

                $stmt->bindparam(":phone1", $phone1);

                $stmt->bindparam(":email1", $email1);

                $stmt->bindparam(":relationship", $relationship);

                //$stmt->execute();

               

            $stmt->execute();

       

            header('location:learnerlogin.php');

            } //4

            catch(PDOException $e){//5

                echo $e->getMessage();

                $conn = null;

        }

   

   

}

?>