Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 11/13/2021 in all areas

  1. You are passing the prices in the post data as the checkbox values, but don't use them (they can be spoofed). Instead use the id to get the price. EXAMPLE <?php $available_seasons = array ( 226 => array ( 'season_name' => '2022 - Season 1', 'season_price' => '25.99', 'season_start_date' => 'Jan. 1, 2022', 'season_end_date' => 'Mar. 31, 2022', 'prize' => 100, ), 227 => array ( 'season_name' => '2022 - Season 2', 'season_price' => '28.99', 'season_start_date' => 'Apr. 1, 2022', 'season_end_date' => 'Jun. 30, 2022', 'prize' => 100, ), 238 => array ( 'season_name' => '2022 - Season 3', 'season_price' => '40.99', 'season_start_date' => 'Jul. 1, 2022', 'season_end_date' => 'Sep. 30, 2022', 'prize' => 230, ), 239 => array ( 'season_id' => 239, 'season_name' => '2022 - Season 4', 'season_price' => '30.65', 'season_start_date' => 'Oct. 1, 2022', 'season_end_date' => 'Dec. 31, 2022', 'prize' => 300, ) ); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $total = 0; echo "<h3>Chosen seasons</h3>"; foreach ($_POST['choice'] as $id => $chosen) { $price = $available_seasons[$id]['season_price']; // get price from your data, not the user $total += $price; echo "{$available_seasons[$id]['season_name']} &mdash; \${$price}<br>"; } echo "<h3>Total due &emsp;\${$total}</h3><hr><br><br>"; exit; } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.3.1.min.js"></script> <script type='text/javascript'> function checkTotal(box) { var sum = parseFloat($("#total").val()) if ( $(box).is(":checked")) { sum += $(box).val() * 1 } else { sum -= $(box).val() * 1 } $("#total").val(sum.toFixed(2)) } </script> </head> <body> <form name='seasonForm' method="post" action=''> <fieldset> <legend>Tickets for Seasons</legend> <?php foreach ( $available_seasons as $k => $season ) { echo "<input name='choice[$k]' class='uk-checkbox' type='checkbox' value='{$season[ 'season_price' ]}' onclick='checkTotal(this)'/> {$season['season_name']}<br>"; } echo "<button type='submit'>Continue</button><br>"; ?> </fieldset> <input id='total' value='0' > </body> </html>
    1 point
  2. Have you got if(isset($_POST['submit'])){ or if(isset($_GET['search'])){
    1 point
  3. Use $_GET['search'] instead of $_POST['search']. If the search=??? is in the url query string, the key/value pair will be put into the GET array. For those times when you are just getting data (as in a search) use GET. If updating something, use POST
    1 point
  4. Name the checkboxes choice[226], choice[227] etc where 226 is your id
    1 point
  5. As you are processing a csv file, use fgetcsv() You indexes for the data are wrong - "dmcnum" will be index [0] (arrays number from 0 by default). You are giving all records inserted the same ID (00001) - not good. Use an auto_incrementing key in your db table. Defore connecting to your DB, call this code below to automate mysql error reporting mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); Forget mysqli and use the superior PDO library (better and easier)
    1 point
  6. Apparently the DateInterval class supports milliseconds, but the default method does not support it as an input value. You need to instead use the createFromDateString class of that method // convert your date to DateTime object $date = '10:00:00.500000'; $dt = new DateTime($date); // convert your period to $interval = '00:25:10.300000'; //Extract time parts list($hours, $minutes, $totalSeconds) = explode(':', $interval); list($wholeSeconds, $milliSeconds) = explode('.', $totalSeconds); //Create interval with milliseconds $intervalString = "{$hours} hours + {$minutes} minutes + {$wholeSeconds} seconds + {$milliSeconds} microseconds"; $interval = DateInterval::createFromDateString($intervalString); // Add interval to date $dt->add($interval);// Format date as you needecho $dt->format('H:i:s'); echo $dt->format('Y-m-d\TH:i:s.u'); //Output: 2021-11-12T10:25:10.800000
    1 point
This leaderboard is set to New York/GMT-05:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.