bineye Posted July 11, 2012 Posted July 11, 2012 Ok, so here's the thing. I'm practicing something, a competition/league organiser script, and I hit a standstill. So, I have a page where I choose number of groups, and number of participants per group. Everything works as it should apart from one thing. The participant's name. When it enters the DB, there is erratic results for the name. I was hoping someone could see the error I made and perhaps help me find a solution. <?php include "config.php"; echo "<h3>New Tournament</h3>"; if($_POST['s2']) { $gettheid=mysql_fetch_assoc(mysql_query("SELECT tid FROM settings WHERE active=1 LIMIT 1")); $maxentry=($_POST['numgrps']*$_POST['tpg']); $z1=1; while($z1 < ($maxentry+1)) { $grpdc=ceil($z1/$_POST['tpg']); mysql_query("INSERT INTO groups VALUES('{$gettheid['tid']}','{$grpdc}','{$_POST[$z1]}','0','0','0','0','0','0','0','0','0')"); $z1++; } echo "League setup complete.<br><a href='index.php'>View</a>"; exit; } if($_POST['s1']) { mysql_query("INSERT INTO settings VALUES(NULL, '{$_POST['name']}', '{$_POST['numgrps']}', '{$_POST['tpg']}', '1')") or die (mysql_error()); $n=0; echo "<form method='post'>"; while($n < $_POST['numgrps']) { $ng=$n+1; echo "<h4>Group {$ng}</h4><table>"; $nt=0; while($nt < $_POST['tpg']) { $ntm=$nt+1; $loop=($nt+1)*$ng; $teamsel=mysql_query("SELECT * FROM teams ORDER BY name"); echo "<tr><td>Team {$ntm}: </td><td><select name='{$loop}'><option value=''>Select...</option>"; while($tmg=mysql_fetch_assoc($teamsel)) { echo "<option value='{$tmg['name']}'>{$tmg['name']}</option>"; } echo "</select></td></tr>"; $nt++; } echo "</table><br />"; $n++; } echo "<input type='hidden' name='numgrps' value='{$_POST['numgrps']}'> <input type='hidden' name='tpg' value='{$_POST['tpg']}'> <input type='hidden' name='s2' value='1'> <input type='submit' value='Submit'></form>"; exit; } echo "<form method='post'> <table><tr><td>Name: </td><td><input type='text' name='name'></td></tr> <tr><td>Number of Groups: </td><td> <select name='numgrps'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> </select></td></tr> <tr><td>Teams per Group: </td><td> <select name='tpg'> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> </select></td></tr></table> <input type='hidden' name='s1' value='1'> <input type='submit' value='Submit'> </form>"; ?> Thanks for reading, and even more thanks if you reply ;) PS I'm well aware of the messiness of the code, but it's only to see if I could get it to work and isn't for going online or anything. Quote
Seker Posted July 11, 2012 Posted July 11, 2012 Shouldn't: <input type='text' name='name'> Be: <input type='text' name='name' method='post'> There's a very good chance that could have nothing to do with it and could be totally wrong, anyway, but... At least I'm trying. :P Quote
bineye Posted July 11, 2012 Author Posted July 11, 2012 Thanks for the reply! No, I have the Post method in the form tag where I believe it should be, besides the other post items work perfectly fine. In fact the problem relates to line 10 and this bugger {$_POST[$z1]}, so I believe the problem areas are lines 24-34. Quote
sniko Posted July 11, 2012 Posted July 11, 2012 Why not try; echo 'Posted Name: '. $_POST['name']; Just to see if it actually has a value. Second, you do not need all those 0's in your query, do the following INSERT INTO <table> (<column1>,<column2>) VALUES (<value1>,<value2>) and set the columns default to x Third, you should have said "A stack of needles, searching for a specific needle" as that is harder to locate, at least the needle is magnetic, therefore, use a metal detector. Of course metaphorically speaking ;) -sniko Quote
HauntedDawg Posted July 11, 2012 Posted July 11, 2012 Can you give an example of the $_POST['name'] you're entering and the value that goes in the database? Quote
bineye Posted July 11, 2012 Author Posted July 11, 2012 Can you give an example of the $_POST['name'] you're entering and the value that goes in the database? Certainly. So I select 2 groups of 6. Group 1 has Teams 1-6 (in order) and 2 has 7-12 (in order) What is input into DB is: Group 1: Team 1 Group 1: Team 7 Group 1: Team 3 Group 1: Team 8 Group 1: Team 5 Group 1: Team 9 Group 2: Group 2: Team 10 Group 2: Group 2: Team 11 Group 2: Group 2: Team 12 I see a pattern there, but I can't exactly find why it is. Quote
HauntedDawg Posted July 12, 2012 Posted July 12, 2012 Okay, i asked for the example you post as your league name, and then what get's entered in your database (to your issue). Secondly, if($_POST['s1']) { mysql_query("INSERT INTO settings VALUES(NULL, '{$_POST['name']}', '{$_POST['numgrps']}', '{$_POST['tpg']}', '1')") or die (mysql_error()); $n=0; Please do not go live with this module with no security in mind. Quote
bineye Posted July 12, 2012 Author Posted July 12, 2012 (edited) Oh, ok, I just wrote "Test 1", and "Test 1" appears in Database, no problem. Please do not go live with this module with no security in mind. Nooooo this is never going onto any website or anything like that. Someone else mailed me with numerous security flaws, but I said in the original post that it was not to be going online. So I neglected security, layout, whatever, bad practice I know, but I just am working through the functions atm. If I ever need to incorporate this, it will be re-written from scratch. Edited July 12, 2012 by bineye Quote
HauntedDawg Posted July 12, 2012 Posted July 12, 2012 If you clean your code a bit and indent it, people will help you a bit more. Not bashing, but as a hint :P Quote
Dave Posted July 12, 2012 Posted July 12, 2012 Indented your code for you. <?php include "config.php"; echo "<h3>New Tournament</h3>"; if ($_POST['s2']) { $gettheid = mysql_fetch_assoc(mysql_query("SELECT tid FROM settings WHERE active=1 LIMIT 1")); $maxentry = ($_POST['numgrps'] * $_POST['tpg']); $z1 = 1; while ($z1 < ($maxentry + 1)) { $grpdc = ceil($z1 / $_POST['tpg']); mysql_query("INSERT INTO groups VALUES('{$gettheid['tid']}','{$grpdc}','{$_POST[$z1]}','0','0','0','0','0','0','0','0','0')"); $z1++; } echo "League setup complete.<a href='index.php'>View</a>"; exit ; } if ($_POST['s1']) { mysql_query("INSERT INTO settings VALUES(NULL, '{$_POST['name']}', '{$_POST['numgrps']}', '{$_POST['tpg']}', '1')") or die(mysql_error()); $n = 0; echo "<form method='post'>"; while ($n < $_POST['numgrps']) { $ng = $n + 1; echo "<h4>Group {$ng}</h4><table>"; $nt = 0; while ($nt < $_POST['tpg']) { $ntm = $nt + 1; $loop = ($nt + 1) * $ng; $teamsel = mysql_query("SELECT * FROM teams ORDER BY name"); echo "<tr><td>Team {$ntm}: </td><td><select name='{$loop}'><option value=''>Select...</option>"; while ($tmg = mysql_fetch_assoc($teamsel)) { echo "<option value='{$tmg['name']}'>{$tmg['name']}</option>"; } echo "</select></td></tr>"; $nt++; } echo "</table>"; $n++; } echo "<input type='hidden' name='numgrps' value='{$_POST['numgrps']}'> <input type='hidden' name='tpg' value='{$_POST['tpg']}'> <input type='hidden' name='s2' value='1'> <input type='submit' value='Submit'></form>"; exit ; } echo "<form method='post'> <table><tr><td>Name: </td><td><input type='text' name='name'></td></tr> <tr><td>Number of Groups: </td><td> <select name='numgrps'> <option value='1'>1</option> <option value='2'>2</option> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> </select></td></tr> <tr><td>Teams per Group: </td><td> <select name='tpg'> <option value='3'>3</option> <option value='4'>4</option> <option value='5'>5</option> <option value='6'>6</option> <option value='7'>7</option> <option value='8'>8</option> </select></td></tr></table> <input type='hidden' name='s1' value='1'> <input type='submit' value='Submit'> </form>"; ?> Quote
HauntedDawg Posted July 13, 2012 Posted July 13, 2012 (edited) I believe you are looking for something along the lines of: <?php $players = array( 1 => array('name' => 'and'), 2 => array('name' => 'irene'), 3 => array('name' => 'gerty'), 4 => array('name' => 'Tops'), 5 => array('name' => 'Franc'), 6 => array('name' => 'engine'), 7 => array('name' => 'bored'), 8 => array('name' => 'mwg'), 9 => array('name' => 'mccodes'), 10 => array('name' => 'nwe'), 11 => array('name' => 'blah'), 12 => array('name' => 'you'), 13 => array('name' => 'me'), 14 => array('name' => 'myself'), ); echo '<br />'; if(isset($_POST['s2'])) { while($a_count < $_POST['numgrps']) { ++$a_count; echo '<h4>Group '.($a_count).'</h4>'; $b_count = 0; while($b_count < $_POST['tpg']) { ++$b_count; echo 'Team '.($b_count).' :: ID ::: '.$_POST[$a_count.'_'.$b_count].' -> NAME ::: '.$players[$_POST[$a_count.'_'.$b_count]]['name'].'<br />'; } } return; } if(isset($_POST['s1'])) { $a_count = 0; $b_count = 0; echo $_POST['name'].' <form method="post">'; while($a_count < $_POST['numgrps']) { ++$a_count; echo '<h4>Group '.($a_count).'</h4> <table>'; $b_count = 0; while($b_count < $_POST['tpg']) { ++$b_count; echo ' <tr> <td>Team '.($b_count).'</td> <td> <select name="'.$a_count.'_'.($b_count).'"> <option value="">Select...</option>'; foreach($players as $player => $db) { echo ' <option value="'.$player.'">'.$db['name'].'</option>'; } echo ' </select> </td> </tr>'; } echo ' </table>'; } echo ' <input type="hidden" name="numgrps" value="'.$_POST['numgrps'].'"> <input type="hidden" name="tpg" value="'.$_POST['tpg'].'"> <input type="hidden" name="s2" value="1"> <input type="hidden" name="name" value="'.$_POST['name'].'"> <input type="submit" value="Submit"></form> </form>'; return; } echo ' <form method="post"> <table> <tr> <td>Name: </td> <td><input type="text" name="name"></td> </tr> <tr> <td>Number of Groups: </td> <td> <select name="numgrps"> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> </td> </tr> <tr> <td>Teams per Group: </td> <td> <select name="tpg"> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> </select> </td> </tr> </table> <input type="hidden" name="s1" value="1"> <input type="submit" value="Submit"> </form>'; ?> The forum has removed a lot of my line breaks. Please see original on http://pastie.org/4248601 Edited July 13, 2012 by HauntedDawg Quote
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.