Registration Form With PDO In PHP


Registration Form With Pdo In Php-
Hello Friends Ajj Me Apko Btaunga Ki Kis Prakar Ham Pdo(Php Data Object Ka Use Karke Registration Form Bana Sakte Hai
.
Steps-
1-Create A File index.php-Sbse Pehle Aap Index.Php Name Ki Ek File Create Kar Lijiye
Ab Is File Me Niche Diya Gya Code Paste Kar Lijiye.

index.php.






<?php



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


$servername = "localhost";

$username = "root";

$password = "";

$dbname = "oops12";



try {



$firstname=$_POST['firstname'];

$lastname=$_POST['lastname'];

$email=$_POST['email'];


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

  

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

$query = $conn->prepare( "SELECT `email` FROM `gajabwap` WHERE `email` = ?" );

$query->bindValue( 1, $email );

$query->execute();


if( $query->rowCount() > 0 ) { # If rows are found for query

     echo "Email alreday registered Please Use Diffrent Email Id!";

}

else {

 
    $sql = "INSERT INTO gajabwap (firstname, lastname, email)

    VALUES ('$firstname', '$lastname', '$email')";

     echo "New record created successfully";

    $conn->exec($sql);

}

   }

catch(PDOException $e)

    {

    echo $sql . "<br>" . $e->getMessage();

    }



$conn = null;



}

?>



<center>

<form method="POST" action="">



<fieldset>

<font  color="red" size="22">Registration Form</font><br>

<br>

firstname

<input type="text" name="firstname" Required=/><br>

Lastname<input type="text" name="lastname" Required=/><br>



Email<input type="text" name="email"/ Required=><br>





<input type="submit" name="submit" value ="save"/>



</fieldset>

</form>

</center>








Yanha Ham Ek Simple Form Bana Rahe Hai  Jisme 3 Fields Hai First Name ,Lastname And Email ,Yanha Hm Sath Me Database Me Jaker Gajabwap Name Se Ek Table Bnaya Hai Jisme 3 Field Create Ki Hai

Is Parkar Hmara Data Form Se Database Me Store Ho Raha Hai.

 Ab Aap Mysql Database Me Gajabwap Table Banakar  4 Fields Create Kar Lijiye Jese Niche Diye Image Me Create Ki Hai.





Is Parkar Aap Easily Php Data Object Ka Use Karke Ek Registration Form Bana Sakte Ho.

Features Of Registration Form-
1-Is  Registration Me Required Html Validation Ka Use Kiya Hai Means Agar Koi User  Directly(Input Field Ko Enter Kiye Bina) Save Par Click Karta Hai To User Ko Message Show Hoga Ki “Required “ .
2-Is Registration Form Me Agar Koi User Email Id Pehle Se He Register Hai Or Fir Be New User Usi Email Id Ka Use Karke Register(Signup) Karne Ki Koshish Karta Hai To User Ke Pass Message Show Hoga Ki” Email Id Already Registered. Please Use Different Email Id “.


Me ummid karta hu ki apko ye Post Achi Lagi Hogi
Thank You

Previous
Next Post »

2 comments

Click here for comments
ssss123456
admin
19 June 2018 at 03:43 ×

very informative post sir..... keep it up great work for freshers

Reply
avatar
Rocky Hill
admin
15 May 2019 at 04:51 ×

Thank you for very usefull information..
Webdesign

Reply
avatar
Thanks for your comment