Advertisement
polectron

Untitled

Dec 4th, 2018
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <html>
  2. <head>
  3.   <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  4. </head>
  5. <body>
  6. <?php
  7.  
  8.     $MYSQLSERVER = "localhost";
  9.     $USER = "root";
  10.     $PASSWORD = "";
  11.     $DATABASE = "registro";
  12.    
  13.     $mysqli = new mysqli($MYSQLSERVER, $USER, $PASSWORD, $DATABASE);
  14.    
  15.     $mysqli->set_charset("utf8");
  16.    
  17.     if ($mysqli->connect_errno) {
  18.         echo "ERROR DB";
  19.     die('Error de conexión: ' . $mysqli->connect_error);
  20.         exit;
  21.     }
  22.  
  23.     if(isset($_REQUEST["player_name"])){            
  24.         $stmt = $mysqli->prepare("INSERT INTO registro (player_name, player_id, type, info) VALUES (?,?,?,?)");
  25.         $stmt->bind_param('ssss',$_REQUEST["player_name"],$_REQUEST["player_id"],$_REQUEST["type"],$_REQUEST["info"]);
  26.        
  27.         print_r($_REQUEST);
  28.        
  29.         if (!$stmt->execute()) {
  30.             echo "ERROR SQL";
  31.             exit;
  32.         }
  33.        
  34.         $stmt->close();
  35.     }else{
  36.         $sql = "SELECT * FROM registro";
  37.        
  38.         $stmt = $mysqli->prepare($sql);
  39.        
  40.         if (!$stmt->execute()) {
  41.             echo "ERROR SQL";
  42.             exit;
  43.         }
  44.        
  45.         $result = $stmt->get_result();
  46.        
  47.         ?>
  48.        
  49.         <table border=1>
  50.             <thead>
  51.             <tr>
  52.               <th>Player ID</th>
  53.               <th>Player Name</th>
  54.               <th>Tipo</th>
  55.               <th>Fecha</th>
  56.               <th>Info</th>
  57.             </tr>
  58.             </thead>
  59.             <tbody>
  60.         <?php
  61.         while($row = $result->fetch_assoc())
  62.         {
  63.             ?>
  64.             <tr>
  65.                 <td><?php echo $row["player_id"];?></td>
  66.                 <td><?php echo $row["player_name"];?></td>
  67.                 <td><?php echo $row["type"];?></td>
  68.                 <td><?php echo $row["date"];?></td>
  69.                 <td><?php echo $row["info"];?></td>
  70.             </tr>
  71.             <?php
  72.         }
  73.         ?>
  74.             </tbody>
  75.         </table>
  76.        
  77.         <?php
  78.         $stmt->close();
  79.     }
  80.    
  81.     $mysqli->close();
  82.    
  83. ?>
  84. </body>
  85. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement