09 PHP application to add new Rows in a Table Program PHP- record

 

Note:- Three programs 

01- index page,

02-connecting database,

03-adding row in a table.

save--index.php

 program:-01

<!DOCTYPE html>
<html>
<head>
<title>Basic MySQLi Commands</title>
</head>
<body>
    <div>
        <form method="POST" action="add.php">
            <label>UserId:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</label><input type="text" name="userid"><br>
            <label>Firstname:</label><input type="text" name="firstname"><br>
            <label>Lastname:</label><input type="text" name="lastname"><br>
            <label>E_Mail:&nbsp;&nbsp;&nbsp;</label><input type="text" name="E_mail"><br>
            <input type="submit" name="add">
        </form>
    </div>
    <br>
    <div>
        <table border="1">
            <thead>
                <th>UserId&nbsp;&nbsp;&nbsp;</th>
                <th>Firstname</th>
                <th>Lastname</th>
                <th>E-Mail&nbsp;&nbsp;&nbsp;</th>                
            </thead>
            <tbody>
                <?php
                    include('conn.php');
                    $query=mysqli_query($conn,"select * from `user`");
                    while($row=mysqli_fetch_array($query)){
                        ?>
                        <tr>
                            <td><?php echo $row['userid']; ?></td>
                            <td><?php echo $row['firstname']; ?></td>
                            <td><?php echo $row['lastname']; ?></td>
                            <td><?php echo $row['E_mail']; ?></td>
                        </tr>
                        <?php
                    }
                ?>
            </tbody>
        </table>
    </div>
</body>
</html>

save--conn.php

 program:-02

 <?php
$conn = mysqli_connect("localhost","root","","ibm_database");
 
// Check connection
if (mysqli_connect_errno())
  {
  echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
?>

 

save--add.php

 program:-03

<?php
    include('conn.php');
 
    $userid=$_POST['userid'];
    $firstname=$_POST['firstname'];
    $lastname=$_POST['lastname'];
    $E_mail=$_POST['E_mail'];
 
    mysqli_query($conn,"insert into `user` (userid,firstname,lastname,E_mail) values ('$userid','$firstname','$lastname','$E_mail')");
    header('location:index.php');
 
?>

 Note:- run to program in local server index.php

Output:-01


 Output:-02


 
Output:-03

add total 5 persons details and submit


 


 

 

 

 

 

 

Comments

Popular posts from this blog

digital marketing ppt-u1

SOFTWARE

cn lab

Computer Operations and Performing - D L Unit-1-1

DBMS Degree Lab Records

DS-Record-mca-04) write a program for evaluating a given postfix expression using stack.

Java unit-1 history , C++ vs Java , java environment

Access the Internet to Browse Infromation & E-Mail Operation- D L Unit-2-1

OAT-Record-01) Visiting card

java program structure,java Tokens, keywords,