test - PHP Online

Form of PHP Sandbox

Enter Your PHP code here for testing/debugging in the Online PHP Sandbox. As in the usual PHP files, you can also add HTML, but do not forget to add the tag <?php in the places where the PHP script should be executed.



Your result can be seen below.

Result of php executing





Full code of test.php

  1. <?php 
  2.  
  3. function serial_query(){
  4.     
  5.     require("connect.php");
  6.     $query = "SELECT MAX(ser) ser FROM `customers`;";
  7.  
  8.     $result = $conn -> query($query);
  9.  
  10.     while ($row = $result -> fetch_assoc()) {
  11.     $ser = $row["ser"] +1 ;
  12.     
  13. }
  14.  
  15. $ser;
  16. return $ser;
  17. }
  18.  
  19. function time_period($P,$d,$ser){
  20.     require("connect.php");
  21.     $date = new DateTime("$d");
  22.     switch ($P) {   
  23.         case "1": // Freeze
  24.             $sql = "select * from `customers`  where `ser` = $ser ";
  25.             $result = mysqli_query($conn, $sql);
  26.             if (mysqli_num_rows($result) > 0) { 
  27.                 while ($row = mysqli_fetch_assoc($result)) {
  28.  
  29.                     $subperiod = $row["subscrip_period"];
  30.                 }
  31.                 switch($subperiod){
  32.                     case "3": // one month
  33.                         $ex_date = 5;
  34.                         date_add($date, date_interval_create_from_date_string("$ex_date days"));
  35.                         break;
  36.                     case "4": // 3 Months
  37.                         $ex_date = 14;
  38.                         date_add($date, date_interval_create_from_date_string("$ex_date days"));
  39.                         break;
  40.                     case "5": // 6 Months
  41.                         $ex_date = 1;
  42.                         date_add($date, date_interval_create_from_date_string("$ex_date months"));
  43.                         break;
  44.                     case "6": // One Year
  45.                         $ex_date = 2;
  46.                         date_add($date, date_interval_create_from_date_string("$ex_date months"));
  47.                         break;
  48.                         
  49.                                 }
  50.             }
  51.                 $expire = date_format($date, "Y-m-d");
  52.             break;
  53.         case "2": // 12 days
  54.             $ex_date = 1;
  55.             date_add($date, date_interval_create_from_date_string("$ex_date months"));
  56.             $expire = date_format($date, "Y-m-d");
  57.             break;
  58.         case "3": // one month
  59.             $ex_date = 1;
  60.             date_add($date, date_interval_create_from_date_string("$ex_date months"));
  61.             $expire = date_format($date, "Y-m-d");
  62.             break;
  63.         case "4": // 3 months
  64.             $ex_date = 3;
  65.             date_add($date, date_interval_create_from_date_string("$ex_date months"));
  66.             $expire = date_format($date, "Y-m-d");
  67.             break;
  68.         case "5": // 6 months
  69.             $ex_date = 6;
  70.             date_add($date, date_interval_create_from_date_string("$ex_date months"));
  71.             $expire = date_format($date, "Y-m-d");
  72.             break;
  73.         case "6": // one year
  74.             $ex_date = 1;
  75.             date_add($date, date_interval_create_from_date_string("$ex_date years"));
  76.             $expire = date_format($date, "Y-m-d");
  77.             break;
  78.         case "8": // 8 session
  79.             $ex_date = 1;
  80.             date_add($date, date_interval_create_from_date_string("$ex_date months"));
  81.             $expire = date_format($date, "Y-m-d");
  82.             break;
  83.         default:
  84.             $ex_date = 0;
  85.     }
  86.     return $expire ;
  87.  
  88. }
  89.  
  90.  
  91.  
  92.  
  93. function _chk(){
  94.     $_date=new DateTime('now');
  95.     if ($_date->format('y') == '24' && $_date->format('m') <= '04' ) {
  96.         return 0;
  97.     } else{ return 1;}
  98.  
  99. }
  100.  
  101. function get_header(){
  102.     
  103.     $header = '
  104.     <!DOCTYPE html>
  105.     <html>
  106.     
  107.     <head>
  108.     
  109.         <meta charset="utf-8">
  110.         <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
  111.         <meta name="description" content="">
  112.         <meta name="author" content="">
  113.         <link href="https://fonts.googleapis.com/css?family=Poppins:100,100i,200,200i,300,300i,400,400i,500,500i,600,600i,700,700i,800,800i,900,900i&display=swap" rel="stylesheet">
  114.     
  115.         <title>FLEET CLUB - GYM</title>
  116.     
  117.         <!-- Additional CSS Files -->
  118.         <link rel="shortcut icon" href="assets/images/mahrosa.png">
  119.     
  120.         <link rel="stylesheet" type="text/css" href="assets/css/bootstrap.min.css">
  121.     
  122.         <link rel="stylesheet" type="text/css" href="assets/css/font-awesome.css">
  123.     
  124.         <link rel="stylesheet" href="assets/css/templatemo-training-studio.css">
  125.         <!-- UIkit CSS -->
  126.         <link rel="stylesheet" href="assets/css/uikit.min.css" />
  127.        <script>
  128.             
  129.        </>  
  130.     </head>
  131.     <body>
  132.         <!-- ***** Preloader Start ***** -->
  133.         <div id="js-preloader" class="js-preloader">
  134.             <div class="preloader-inner">
  135.                 <span class="dot"></span>
  136.                 <div class="dots">
  137.                     <span></span>
  138.                     <span></span>
  139.                     <span></span>
  140.                 </div>
  141.             </div>
  142.         </div>
  143.         <!-- ***** Preloader End ***** -->  
  144.         <!-- ***** Header Area Start ***** -->
  145.         <header class="header-area header-sticky">
  146.             <div class="container">
  147.                 <div class="row">
  148.                     <!-- <div class="col-1">
  149.                         <img   style="width: 60px;height: 50px;position: relative;top:10px;left:1px" src="assets/images/mahrosa.png">
  150.                     </div> -->
  151.                     <div class="col-12">
  152.                         <nav class="main-nav">
  153.                             <!-- ***** Logo Start ***** -->
  154.                             <a href="index.php" class="logo">FLEET CLUB<em> GYM</em></a>
  155.                             <!-- ***** Logo End ***** -->
  156.                             <!-- ***** Menu Start ***** -->
  157.                             <ul class="nav">
  158.                                 <li class="scroll-to-section"><a href="index.php" class="active">Home</a></li>
  159.                             </ul>
  160.                             <a class="menu-trigger">
  161.                                 <span>Menu</span>
  162.                             </a>
  163.                             <!-- ***** Menu End ***** -->
  164.                         </nav>
  165.                     </div>
  166.                 </div>
  167.             </div>
  168.         </header>
  169.         <!-- ***** Header Area End ***** -->
  170.     ';
  171.     return $header;
  172. }
  173.  
  174. function get_footer(){ 
  175.     $footer = 
  176.     
  177.     <!-- ***** Footer Start ***** -->
  178. <footer>
  179.     <div class="container">
  180.         <div class="row">
  181.             <div class="col-lg-12">
  182.                 <p>Copyright © 2023 Fleet Club <em style="color:var(--orange);font-size:15px;">Mahrousa</em> - IT Team
  183.                     - Designed by - Tarek Youssef </p>
  184.             </div>
  185.         </div>
  186.     </div>
  187. </footer>
  188.  
  189. <!-- jQuery -->
  190. <script src="assets/js/jquery-2.1.0.min.js"></script>
  191. <script src="assets/js/3.7.1jquery.min.js"></script>
  192. <!-- Bootstrap -->
  193. <script src="assets/js/popper.js"></script>
  194. <script src="assets/js/bootstrap.min.js"></script>
  195. <!-- UIkit JS -->
  196. <script src="assets/js/uikit.min.js"></script>
  197. <script src="assets/js/uikit-icons.min.js"></script>
  198. <!-- Plugins -->
  199. <script src="assets/js/scrollreveal.min.js"></script>
  200. <script src="assets/js/waypoints.min.js"></script>
  201. <script src="assets/js/jquery.counterup.min.js"></script>
  202. <script src="assets/js/imgfix.min.js"></script>
  203. <script src="assets/js/mixitup.js"></script>
  204. <script src="assets/js/accordions.js"></script>
  205.  
  206. <!-- Global Init -->
  207. <script src="assets/js/custom.js"></script>
  208. <script>
  209.     (() => {
  210.         "use strict"
  211.         // Fetch all the forms we want to apply custom Bootstrap validation styles to
  212.         const forms = document.querySelectorAll(".needs-validation")
  213.         // Loop over them and prevent submission
  214.         Array.from(forms).forEach(form => {
  215.             form.addEventListener("submit", event => {
  216.                 if (!form.checkValidity()) {
  217.                     event.preventDefault()
  218.                     event.stopPropagation()
  219.                 }
  220.                 form.classList.add("was-validated")
  221.             }, false)
  222.         })
  223.     })();
  224.     document.getElementById("main_form").addEventListener("submit", function(event) {
  225.         var gen = document.forms["main_form"]["gender"];
  226.         var subtype = document.forms["main_form"]["subtype"];
  227.         if (gen[0].checked === false && gen[1].checked === false) {
  228.             event.preventDefault(); // Prevent form submission
  229.             alert("برجاء تحديد النوع"); // Display an error message
  230.         } else if (subtype[0].checked === false && subtype[1].checked === false && subtype[2].checked === false) {
  231.             event.preventDefault(); // Prevent form submission
  232.             alert("برجاء تحديد نوع الاشتراك"); // Display an error message
  233.         }
  234.     });
  235.     // search:
  236.     $(document).ready(function() {
  237.         $("#live_search").keyup(function() {
  238.             var input = $(this).val();
  239.             if (input != "") {
  240.                 $.ajax({
  241.                     url: "livesearch.php",
  242.                     method: "POST",
  243.                     data: {
  244.                         input: input
  245.                     },
  246.                     success: function(data) {
  247.                         $("#searchResult").html(data);
  248.                     }
  249.                 })
  250.             } else {
  251.                 $("#searchResult").css("Display", "none");
  252.             }
  253.         });
  254.     });
  255. </script>
  256. </body>
  257. </html>';
  258. return $footer;
  259. }
  260.  
  261. function get_data($df,$dt){
  262.     require ("connect.php");
  263.     $arr=["12 حصة","شهري","3 شهور","6شهور","سنوي"];
  264.     $condition_date ="`subscrip_date` BETWEEN '$df 00:00:01' AND '$dt 23:59:59'";
  265.     echo '<table style="text-align:center;" class="table table-dark table-hover table-bordered"><tr>
  266.     <th rowspan="2">نوع الاشتراك</th>
  267.     <th colspan="2">قوات مسلحة</th>
  268.     <th colspan="2">محروسة</th>
  269.     <th colspan="2">مدني</th>
  270.     <!--<th rowspan="2" >الإجمالي </th>-->
  271.     </tr>
  272.     <tr>
  273.     <th>رجال</th>
  274.     <th>سيدات </th>
  275.     <th>رجال</th>
  276.     <th>سيدات </th>
  277.     <th>رجال</th>
  278.     <th>سيدات </th>
  279.     </tr>';
  280.     for ($sub_period=2; $sub_period<=6  ; $sub_period++) {
  281.         echo "<tr> <th>".$arr[$sub_period-2]."</th>"; 
  282.         for ($sub_type= 1; $sub_type<=3; $sub_type++) {
  283.             for ($g= 1; $g<=2; $g++) {
  284.                 $sql = "SELECT COUNT(*) FROM `customers` WHERE `gender` = $g  AND `subscrip_period` = $sub_period AND `subtype` = $sub_type AND".$condition_date;
  285.                 $result = mysqli_query($conn, $sql);
  286.                 while ($row = mysqli_fetch_assoc($result)) {
  287.                     $ss = $row["COUNT(*)"];
  288.                     echo "<th>" . $ss .  "</th>";
  289.                 }
  290.             }
  291.         }
  292.         // $tot = "SELECT COUNT(*) FROM `customers`Where `subscrip_period` = $sub_period AND" . $condition_date;
  293.         // $result = mysqli_query($conn, $tot);
  294.         // while ($row = mysqli_fetch_assoc($result)) {
  295.         //     $ss = $row["COUNT(*)"];
  296.         //     echo "<th>" . $ss . "</th>";
  297.         // }
  298.     }
  299.     
  300.         //Total Row: 
  301.         echo "<tr>
  302.         <th>الاجمالي</th>"; 
  303.         for ($sub_type= 1; $sub_type<=3; $sub_type++) {
  304.             for ($g= 1; $g<=2; $g++) {
  305.                 $sql = "SELECT COUNT(*) FROM `customers` WHERE `gender` = $g  AND `subtype` = $sub_type AND ".$condition_date;
  306.                 $result = mysqli_query($conn, $sql);
  307.                 while ($row = mysqli_fetch_assoc($result)) {
  308.                     $ss = $row["COUNT(*)"];
  309.                     echo "<th>" . $ss . "</th>";
  310.                     }
  311.                 }
  312.             }
  313.             //Last Row
  314.             $sql = "SELECT COUNT(*) FROM `customers` WHERE ".$condition_date;
  315.             $result = mysqli_query($conn, $sql);
  316.             while ($row = mysqli_fetch_assoc($result)) {
  317.                 $ss = $row["COUNT(*)"];
  318.             echo ' <tr>
  319.                     <th  colspan="4">إجمالي الأعضاء المشتركين</th>
  320.                     <th colspan="4">'.$ss.'</th>
  321.                     </tr>';
  322.             }
  323.         echo"</tr></table>";
  324.     }
  325.  
  326. function get_data2($f,$t){
  327.     require ("connect.php");
  328.     $fdate = date_create($f);
  329.     date_modify($fdate, '-1 month');
  330.     $newfDate = date_format($fdate, 'Y-m-d');
  331.  
  332.     $tdate = date_create($t);
  333.     date_modify($tdate, '-1 month');
  334.     $newtDate = date_format($tdate, 'Y-m-d');
  335.  
  336.     //echo"<h4 style='color:white'>$newfDate -->$newtDate</h4> ";
  337.  
  338.  
  339. echo
  340.     '
  341. <table style="text-align:center;"  class="table table-dark table-hover table-bordered">
  342. <tr>
  343.     <th rowspan="2">نوع الاشتراك</th>
  344.     <th colspan="2">قوات مسلحة</th>
  345.     <th colspan="2">محروسة</th>
  346.     <th colspan="2">مدني</th>
  347. </tr>
  348. <tr>
  349. <th>رجال</th>
  350. <th>سيدات </th>
  351. <th>رجال</th>
  352. <th>سيدات </th>
  353. <th>رجال</th>
  354. <th>سيدات </th>
  355. </tr>
  356. <tr>
  357. <th></th>
  358. ';
  359.  
  360.     for ($sub_type= 1; $sub_type<=3; $sub_type++) {
  361.         for ($g= 1; $g<=2; $g++) {
  362.             $sql = "SELECT COUNT(*) FROM `customers` WHERE `gender` = $g   AND `subtype` = $sub_type AND `subscrip_ex` BETWEEN '$newfDate' AND '$newtDate'";
  363.             $result = mysqli_query($conn, $sql);
  364.             while ($row = mysqli_fetch_assoc($result)) {
  365.                 $ss = $row["COUNT(*)"];
  366.                 echo "<th>" . $ss .  "</th>";
  367.             }
  368.         }
  369.     }
  370. echo "</table>";
  371. }
  372.  
  373. function upload_imgs($ser,$filename)
  374. {   
  375.      //=====================[  Upload Image  ]==============================
  376.    
  377.      try {
  378.         // Create the 'profiles/newfolder' directory if it doesn't exist
  379.         if (!is_dir('profiles/newfolder')) {
  380.             mkdir('profiles/newfolder', 0777, true);
  381.             // Rename the 'profiles/newfolder' directory to 'profiles/$ser'
  382.             rename('profiles/newfolder', 'profiles/' . $ser);
  383.         }
  384.     } catch (Exception $e) {
  385.         // If an error occurs, display the error message
  386.         echo "Error: couldn't create file !" . $e->getMessage();
  387.     }
  388.  
  389.  $target_dir = "profiles/$ser";
  390.  $target_file = $target_dir . basename($_FILES[$filename]["name"]); 
  391.  $uploadOk = 1;
  392.  $imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
  393.  
  394.  
  395.     // Check if image file is a actual image or fake image
  396.     if (isset($_POST["submit"])) {
  397.         $check = getimagesize($_FILES[$filename]["tmp_name"]);
  398.         if ($check !== false) {
  399.             echo "File is an image - " . $check["mime"] . ".";
  400.             $uploadOk = 1;
  401.         } else {
  402.             echo "File is not an image.";
  403.             $uploadOk = 0;
  404.         }
  405.     }
  406.     // Rename file
  407. $Extantion = pathinfo($target_file, PATHINFO_EXTENSION);
  408. $randam = rand(0,99);
  409. $rename = $ser."-".$randam;
  410. $newfilename = $rename.".".$Extantion;
  411.  
  412.     // Check if file already exists
  413.     if (file_exists($newfilename)) {
  414.      //   echo "Sorry, file already exists.";
  415.         $uploadOk = 0;
  416.     }
  417.  
  418.     // Check file size
  419.     if ($_FILES[$filename]["size"] > 5000000) { //5MB
  420.        // echo "Sorry, your file is too large.";
  421.         $uploadOk = 0;
  422. }
  423.  
  424.     // Allow certain file formats
  425.     if (
  426.         $imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
  427.         && $imageFileType != "gif" && $imageFileType != "jfif"
  428.     ) {
  429.        // echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
  430.         $uploadOk = 0;
  431.     }
  432.  
  433.                 // Check if $uploadOk is set to 0 by an error
  434.                 if ($uploadOk == 0) {
  435.                    // echo "Sorry, your file was not uploaded.";
  436.                     // if everything is ok, try to upload file
  437.                 } else {
  438.                     if (move_uploaded_file($_FILES[$filename]["tmp_name"],$target_dir.'/'.$newfilename)) {
  439.                         $FILE_NAME = $target_dir.'/'.$newfilename;
  440.                         require("connect.php");
  441.                             $update = "UPDATE `customers` SET `profile_img` ='$FILE_NAME' WHERE `ser` = '$ser'";
  442.                             $conn->query($update);
  443.                        //echo "The file " . htmlspecialchars(basename($_FILES[$filename]["name"])) . " has been uploaded.";
  444.                     } else {
  445.                         echo "Sorry, there was an error uploading your file.";
  446.                     }
  447.                 }
  448.             
  449.  
  450. }
  451.  
  452.  
  453. //Barcode Generator
  454. function generateBarcode($text) {
  455.     require_once('vendor/autoload.php'); // Path to autoload.php file of TCPDF library
  456.     $barcodeobj = new TCPDFBarcode($text, 'C39');
  457.       $barcode = $barcodeobj->getBarcodeSVGcode(1, 30, '#04047f');
  458.       $barcode = strtolower($barcode); // Convert the SVG code to lowercase
  459.       return $barcode;
  460.   }
  461.  
  462. ?>
File Description
  • test
  • PHP Code
  • 28 Mar-2024
  • 16.44 Kb
You can Share it: