OutOfInk Posted March 9, 2014 Share Posted March 9, 2014 (edited) I am attempting to build a football punting website with two teams and an option for a draw. Each week can be anywhere form one team playing or three. I need to catch the data from the checkboxes and the bet amount. Below is my code. I havent coded for a few years now and i cannot find anywhere on how to catch the data and turn it into a array, so i can sort each bet on the team checked and the bet and save the data into a mysql db. Any help thanks in advance <?php if (isset($_POST['beton'])){ $ints = NULL; foreach ($_POST['beton'] as $key => $value) { $ints .= "$value, "; } $ints = substr($ints, 0, -2); $interests = true; }else{ $interests = NULL; echo "No games selected!"; } //////////////////////////// BEt AMOUNT if (isset($_POST['amount'])){ $bet = NULL; foreach ($_POST['amount'] as $key => $value) { $bet .= "$value, "; } $bet = substr($bet, 0, -2); $interes = true; }else{ $interes = NULL; echo "No games selected!"; } if ($interests){ echo "$ints - $bet"; } // THIS SHOWS THE DATA but as one whole string, i need to split and shove it into an array $start_date = date("d/m/Y", strtotime("- 7 days")); $end_date = date("d/m/Y", strtotime("+ 7 days")); echo " $start_date - $end_date"; // Order by current time and date, must make function where if no bet is placed and time and date has passed minus 20 credits $leader = mysql_query("SELECT mysql data... ORDER BY `Date`"); while ($redeal = mysql_fetch_row($leader)){ echo "<tr class=innertable bgcolor=$bgcolor>"; echo "<td align=left>$redeal[0] ($<b>".number_format(0.00)."</b>)</td><td><input type='checkbox' name='beton[]' value='$redeal[0]' /></td>"; echo "<td>V's</td>"; echo "<td align=left>$redeal[1] ($<b>".number_format(0.00)."</b>)</td><td><input type='checkbox' name='beton[]' value='$redeal[1]' /></td>"; echo "<td align=left>$51.00 <input type='checkbox' name='beton[]' value='Draw-$redeal[5]-$redeal[6]' /></td>"; echo "<td align=left>$redeal[2]</td>"; echo "<td class=innertable align=right><input type='text' size='5' class='input' name='amount[]'></td></tr>"; } ?> <input type="submit" name="placebet" class="input" value="Submit my bet!" /> Edited March 9, 2014 by OutOfInk Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 9, 2014 Share Posted March 9, 2014 ok - need more input, but first you need more coding. 1 - please use the tags here to encase your code so it is more readable. 2 - you need to close your form 3 - you do realize that your inputs using 'beton[]' as the name attribute are returning an array in the $_POST array? Meaning you already have an array, so I don't know what you mean by "turn it into [an] array". 4 - your foreach to grab the contents of the beton[] array, could be entirely replaced with: $ints = $_POST['beton'] to create an array of all the checkboxes named beton. Same with your 'amount[]' array from $_POST. 5 - Do you need to validate the inputs from beton and amount to ensure that they are one-to-one, meaning you have a bet AND amount for each choice(?) ? You have a pseudo query in here - perhaps if you flesh it out we can see what your data looks like. What you have given us is very hard to figure out. And your html form shows stuff that you have not declared for us to see, so hard to make sense of it. Maybe laying out in English what you are doing will help us to see what you see. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.