3v4l.org

run code in 300+ PHP versions simultaneously
<?php // Step 1: Connect to the database $conn = new mysqli("localhost", "root", "", "customer_db"); // Check connection if ($conn->connect_error) { die("Connection failed: " . $conn->connect_error); } // Step 2: Handle form submission if ($_SERVER["REQUEST_METHOD"] == "POST") { $customer_name = $_POST['customer_name']; $email = $_POST['email']; $phone_number = $_POST['phone_number']; $account_type = $_POST['account_type']; $principal = $_POST['principal']; // Calculate interest based on account type $interest = 0; if ($account_type == "Saving") { $interest = $principal * 0.06; // 6% interest } elseif ($account_type == "Fixed Deposit") { $interest = $principal * 0.10; // 10% interest } // Insert data into the database $sql = "INSERT INTO customers (customer_name, email, phone_number, account_type, principal, interest) VALUES ('$customer_name', '$email', '$phone_number', '$account_type', '$principal', '$interest')"; if ($conn->query($sql) === TRUE) { echo "Customer data inserted successfully!"; } else { echo "Error: " . $sql . "<br>" . $conn->error; } } ?> <!DOCTYPE html> <html> <head> <title>Customer Management</title> </head> <body> <h1>Customer Management Form</h1> <!-- Step 3: Form to input data --> <form method="POST" action=""> <label>Customer Name:</label> <input type="text" name="customer_name" required><br><br> <label>Email:</label> <input type="email" name="email" required><br><br> <label>Phone Number:</label> <input type="text" name="phone_number" required><br><br> <label>Account Type:</label> <select name="account_type" required> <option value="Saving">Saving</option> <option value="Current">Current</option> <option value="Fixed Deposit">Fixed Deposit</option> </select><br><br> <label>Principal Amount:</label> <input type="number" name="principal" required><br><br> <button type="submit">Submit</button> </form> <h2>Customer Details</h2> <!-- Step 4: Display data --> <?php $sql = "SELECT * FROM customers"; $result = $conn->query($sql); if ($result->num_rows > 0) { echo "<table border='1'> <tr> <th>Customer Name</th> <th>Email</th> <th>Phone Number</th> <th>Account Type</th> <th>Principal</th> <th>Interest</th> </tr>"; while ($row = $result->fetch_assoc()) { echo "<tr> <td>{$row['customer_name']}</td> <td>{$row['email']}</td> <td>{$row['phone_number']}</td> <td>{$row['account_type']}</td> <td>{$row['principal']}</td> <td>{$row['interest']}</td> </tr>"; } echo "</table>"; } else { echo "No customer records found!"; } $conn->close(); ?> </body> </html>
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 9, Position 2 = 12
Branch analysis from position: 9
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 12
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 67
Branch analysis from position: 16
2 jumps found. (Code = 43) Position 1 = 34, Position 2 = 37
Branch analysis from position: 34
1 jumps found. (Code = 42) Position 1 = 41
Branch analysis from position: 41
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
1 jumps found. (Code = 42) Position 1 = 67
Branch analysis from position: 67
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 104
Branch analysis from position: 76
1 jumps found. (Code = 42) Position 1 = 98
Branch analysis from position: 98
2 jumps found. (Code = 44) Position 1 = 102, Position 2 = 78
Branch analysis from position: 102
1 jumps found. (Code = 42) Position 1 = 105
Branch analysis from position: 105
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 78
2 jumps found. (Code = 44) Position 1 = 102, Position 2 = 78
Branch analysis from position: 102
Branch analysis from position: 78
Branch analysis from position: 104
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 62
2 jumps found. (Code = 43) Position 1 = 76, Position 2 = 104
Branch analysis from position: 76
Branch analysis from position: 104
Branch analysis from position: 37
2 jumps found. (Code = 43) Position 1 = 39, Position 2 = 41
Branch analysis from position: 39
2 jumps found. (Code = 43) Position 1 = 60, Position 2 = 62
Branch analysis from position: 60
Branch analysis from position: 62
Branch analysis from position: 41
Branch analysis from position: 67
filename:       /in/0cJag
function name:  (null)
number of ops:  109
compiled vars:  !0 = $conn, !1 = $customer_name, !2 = $email, !3 = $phone_number, !4 = $account_type, !5 = $principal, !6 = $interest, !7 = $sql, !8 = $result, !9 = $row
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    3     0  E >   NEW                                              $10     'mysqli'
          1        SEND_VAL_EX                                              'localhost'
          2        SEND_VAL_EX                                              'root'
          3        SEND_VAL_EX                                              ''
          4        SEND_VAL_EX                                              'customer_db'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $10
    6     7        FETCH_OBJ_R                                      ~13     !0, 'connect_error'
          8      > JMPZ                                                     ~13, ->12
    7     9    >   FETCH_OBJ_R                                      ~14     !0, 'connect_error'
         10        CONCAT                                           ~15     'Connection+failed%3A+', ~14
         11      > EXIT                                                     ~15
   11    12    >   FETCH_R                      global              ~16     '_SERVER'
         13        FETCH_DIM_R                                      ~17     ~16, 'REQUEST_METHOD'
         14        IS_EQUAL                                                 ~17, 'POST'
         15      > JMPZ                                                     ~18, ->67
   12    16    >   FETCH_R                      global              ~19     '_POST'
         17        FETCH_DIM_R                                      ~20     ~19, 'customer_name'
         18        ASSIGN                                                   !1, ~20
   13    19        FETCH_R                      global              ~22     '_POST'
         20        FETCH_DIM_R                                      ~23     ~22, 'email'
         21        ASSIGN                                                   !2, ~23
   14    22        FETCH_R                      global              ~25     '_POST'
         23        FETCH_DIM_R                                      ~26     ~25, 'phone_number'
         24        ASSIGN                                                   !3, ~26
   15    25        FETCH_R                      global              ~28     '_POST'
         26        FETCH_DIM_R                                      ~29     ~28, 'account_type'
         27        ASSIGN                                                   !4, ~29
   16    28        FETCH_R                      global              ~31     '_POST'
         29        FETCH_DIM_R                                      ~32     ~31, 'principal'
         30        ASSIGN                                                   !5, ~32
   19    31        ASSIGN                                                   !6, 0
   20    32        IS_EQUAL                                                 !4, 'Saving'
         33      > JMPZ                                                     ~35, ->37
   21    34    >   MUL                                              ~36     !5, 0.06
         35        ASSIGN                                                   !6, ~36
   20    36      > JMP                                                      ->41
   22    37    >   IS_EQUAL                                                 !4, 'Fixed+Deposit'
         38      > JMPZ                                                     ~38, ->41
   23    39    >   MUL                                              ~39     !5, 0.1
         40        ASSIGN                                                   !6, ~39
   27    41    >   ROPE_INIT                                    13  ~42     'INSERT+INTO+customers+%28customer_name%2C+email%2C+phone_number%2C+account_type%2C+principal%2C+interest%29%0A++++++++++++VALUES+%28%27'
   28    42        ROPE_ADD                                      1  ~42     ~42, !1
         43        ROPE_ADD                                      2  ~42     ~42, '%27%2C+%27'
         44        ROPE_ADD                                      3  ~42     ~42, !2
         45        ROPE_ADD                                      4  ~42     ~42, '%27%2C+%27'
         46        ROPE_ADD                                      5  ~42     ~42, !3
         47        ROPE_ADD                                      6  ~42     ~42, '%27%2C+%27'
         48        ROPE_ADD                                      7  ~42     ~42, !4
         49        ROPE_ADD                                      8  ~42     ~42, '%27%2C+%27'
         50        ROPE_ADD                                      9  ~42     ~42, !5
         51        ROPE_ADD                                     10  ~42     ~42, '%27%2C+%27'
         52        ROPE_ADD                                     11  ~42     ~42, !6
         53        ROPE_END                                     12  ~41     ~42, '%27%29'
   27    54        ASSIGN                                                   !7, ~41
   30    55        INIT_METHOD_CALL                                         !0, 'query'
         56        SEND_VAR_EX                                              !7
         57        DO_FCALL                                      0  $50     
         58        TYPE_CHECK                                    8          $50
         59      > JMPZ                                                     ~51, ->62
   31    60    >   ECHO                                                     'Customer+data+inserted+successfully%21'
   30    61      > JMP                                                      ->67
   33    62    >   CONCAT                                           ~52     'Error%3A+', !7
         63        CONCAT                                           ~53     ~52, '%3Cbr%3E'
         64        FETCH_OBJ_R                                      ~54     !0, 'error'
         65        CONCAT                                           ~55     ~53, ~54
         66        ECHO                                                     ~55
   37    67    >   ECHO                                                     '%0A%3C%21DOCTYPE+html%3E%0A%3Chtml%3E%0A%3Chead%3E%0A++++%3Ctitle%3ECustomer+Management%3C%2Ftitle%3E%0A%3C%2Fhead%3E%0A%3Cbody%3E%0A++++%3Ch1%3ECustomer+Management+Form%3C%2Fh1%3E%0A%0A++++%3C%21--+Step+3%3A+Form+to+input+data+--%3E%0A++++%3Cform+method%3D%22POST%22+action%3D%22%22%3E%0A++++++++%3Clabel%3ECustomer+Name%3A%3C%2Flabel%3E%0A++++++++%3Cinput+type%3D%22text%22+name%3D%22customer_name%22+required%3E%3Cbr%3E%3Cbr%3E%0A%0A++++++++%3Clabel%3EEmail%3A%3C%2Flabel%3E%0A++++++++%3Cinput+type%3D%22email%22+name%3D%22email%22+required%3E%3Cbr%3E%3Cbr%3E%0A%0A++++++++%3Clabel%3EPhone+Number%3A%3C%2Flabel%3E%0A++++++++%3Cinput+type%3D%22text%22+name%3D%22phone_number%22+required%3E%3Cbr%3E%3Cbr%3E%0A%0A++++++++%3Clabel%3EAccount+Type%3A%3C%2Flabel%3E%0A++++++++%3Cselect+name%3D%22account_type%22+required%3E%0A++++++++++++%3Coption+value%3D%22Saving%22%3ESaving%3C%2Foption%3E%0A++++++++++++%3Coption+value%3D%22Current%22%3ECurrent%3C%2Foption%3E%0A++++++++++++%3Coption+value%3D%22Fixed+Deposit%22%3EFixed+Deposit%3C%2Foption%3E%0A++++++++%3C%2Fselect%3E%3Cbr%3E%3Cbr%3E%0A%0A++++++++%3Clabel%3EPrincipal+Amount%3A%3C%2Flabel%3E%0A++++++++%3Cinput+type%3D%22number%22+name%3D%22principal%22+required%3E%3Cbr%3E%3Cbr%3E%0A%0A++++++++%3Cbutton+type%3D%22submit%22%3ESubmit%3C%2Fbutton%3E%0A++++%3C%2Fform%3E%0A%0A++++%3Ch2%3ECustomer+Details%3C%2Fh2%3E%0A%0A++++%3C%21--+Step+4%3A+Display+data+--%3E%0A++++'
   74    68        ASSIGN                                                   !7, 'SELECT+%2A+FROM+customers'
   75    69        INIT_METHOD_CALL                                         !0, 'query'
         70        SEND_VAR_EX                                              !7
         71        DO_FCALL                                      0  $57     
         72        ASSIGN                                                   !8, $57
   77    73        FETCH_OBJ_R                                      ~59     !8, 'num_rows'
         74        IS_SMALLER                                               0, ~59
         75      > JMPZ                                                     ~60, ->104
   78    76    >   ECHO                                                     '%3Ctable+border%3D%271%27%3E%0A++++++++++++++++%3Ctr%3E%0A++++++++++++++++++++%3Cth%3ECustomer+Name%3C%2Fth%3E%0A++++++++++++++++++++%3Cth%3EEmail%3C%2Fth%3E%0A++++++++++++++++++++%3Cth%3EPhone+Number%3C%2Fth%3E%0A++++++++++++++++++++%3Cth%3EAccount+Type%3C%2Fth%3E%0A++++++++++++++++++++%3Cth%3EPrincipal%3C%2Fth%3E%0A++++++++++++++++++++%3Cth%3EInterest%3C%2Fth%3E%0A++++++++++++++++%3C%2Ftr%3E'
   87    77      > JMP                                                      ->98
   88    78    >   ROPE_INIT                                    13  ~68     '%3Ctr%3E%0A++++++++++++++++++++%3Ctd%3E'
   89    79        FETCH_DIM_R                                      ~61     !9, 'customer_name'
         80        ROPE_ADD                                      1  ~68     ~68, ~61
         81        ROPE_ADD                                      2  ~68     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++++%3Ctd%3E'
   90    82        FETCH_DIM_R                                      ~62     !9, 'email'
         83        ROPE_ADD                                      3  ~68     ~68, ~62
         84        ROPE_ADD                                      4  ~68     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++++%3Ctd%3E'
   91    85        FETCH_DIM_R                                      ~63     !9, 'phone_number'
         86        ROPE_ADD                                      5  ~68     ~68, ~63
         87        ROPE_ADD                                      6  ~68     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++++%3Ctd%3E'
   92    88        FETCH_DIM_R                                      ~64     !9, 'account_type'
         89        ROPE_ADD                                      7  ~68     ~68, ~64
         90        ROPE_ADD                                      8  ~68     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++++%3Ctd%3E'
   93    91        FETCH_DIM_R                                      ~65     !9, 'principal'
         92        ROPE_ADD                                      9  ~68     ~68, ~65
         93        ROPE_ADD                                     10  ~68     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++++%3Ctd%3E'
   94    94        FETCH_DIM_R                                      ~66     !9, 'interest'
         95        ROPE_ADD                                     11  ~68     ~68, ~66
         96        ROPE_END                                     12  ~67     ~68, '%3C%2Ftd%3E%0A++++++++++++++++++%3C%2Ftr%3E'
         97        ECHO                                                     ~67
   87    98    >   INIT_METHOD_CALL                                         !8, 'fetch_assoc'
         99        DO_FCALL                                      0  $75     
        100        ASSIGN                                           ~76     !9, $75
        101      > JMPNZ                                                    ~76, ->78
   97   102    >   ECHO                                                     '%3C%2Ftable%3E'
   77   103      > JMP                                                      ->105
   99   104    >   ECHO                                                     'No+customer+records+found%21'
  102   105    >   INIT_METHOD_CALL                                         !0, 'close'
        106        DO_FCALL                                      0          
  104   107        ECHO                                                     '%3C%2Fbody%3E%0A%3C%2Fhtml%3E'
  105   108      > RETURN                                                   1

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
140.47 ms | 1002 KiB | 13 Q