Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <head>
- <title>insert data in database using mysqli</title>
- </head>
- <body>
- <div id="main">
- <h1>Insert data into database using mysqli</h1>
- <div id="login">
- <h2>Friends Form</h2>
- <hr/>
- <form action="" method="post">
- <label>ID :</label>
- <input type="text" name="id" id="id"><br /><br />
- <label>firstname :</label>
- <input type="text" name="firstname" id="firstname"><br/><br />
- <label>lastname :</label>
- <input type="text" name="lastname" id="lastname"><br/><br/>
- <label>email :</label>
- <input type="text" name="email" id="email"><br/><br/>
- <input type="submit" value=" Submit " name="submit"/><br />
- </form>
- </div>
- <?php
- if(isset($_POST["submit"])){
- $servername = "localhost";
- $username = "amal";
- $password = "amal";
- $dbname = "myamal";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "INSERT INTO myfriends (id,firstname, lastname,email,reg_date)
- VALUES ('".$_POST["id"]."','".$_POST["firstname"]."', '".$_POST["lastname"]."','".$_POST["email"]."',CURRENT_TIMESTAMP);";
- if ($conn->query($sql) === TRUE) {
- echo "<script type= 'text/javascript'>alert('New record created successfully');</script>";
- } else {
- echo "<script type= 'text/javascript'>alert('Error: insert failed');</script>";
- }
- $conn->close();
- }
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement