Jorn Posted May 2, 2012 Author Share Posted May 2, 2012 Well been reading for long time actually but obviously not long enough haha tried your new code but it does something odd: when I start the page without even selecting a player I get a warning: The player Warning: implode(): Invalid arguments passed in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 164 has been assigned to the poker tournament Line 164 holds the Implode obviously. (its 164 when I copy paste your code it adds loads of spaces in lines for some reason). when I select some players and hit ADD , I get: no players where found. Try again later Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 2, 2012 Author Share Posted May 2, 2012 Have to get some sleep now, not seeing straight anymore (1:30 am here in Netherlands). Ill continue this in the morning thanks for all the help sofar! made some real progress Quote Link to comment Share on other sites More sharing options...
creata.physics Posted May 2, 2012 Share Posted May 2, 2012 That's my fault. I should have taken that into consideration. You can add this code where ever you want. $players_added = ''; if( isset( $cgi->getValue('playerid') ) ) { $player_list = implode( ',', $cgi->getValue('playerid') ); $players_added = "<p align='center' class='red'>The player(s): <strong>$player_list</strong> have been assigned to the poker tournament.</p>"; } You can then replace: <p align="center" class="red">The player(s): <strong><?php echo implode(',', $cgi->getValue('playerid') ); ?></strong> have been assigned to the poker tournament.</p> with: <?php echo $players_added; ?> That should fix the issue. Quote Link to comment Share on other sites More sharing options...
Jessica Posted May 3, 2012 Share Posted May 3, 2012 Rather than a loop for the text you could use implode. I didn't say along with a loop, I said rather than. It's fairly obvious from the output what you are doing "wrong". You should brush up on these basic functions Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 3, 2012 Author Share Posted May 3, 2012 Thanks for the update Creata.physics! added the code and then replaced the echo with the one you suggested. on loading the page i get white page with: Fatal error: Can't use method return value in write context in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 58 line 58: if( isset( $cgi->getValue('playerid') ) ) Quote Link to comment Share on other sites More sharing options...
creata.physics Posted May 3, 2012 Share Posted May 3, 2012 That's fine. Try changing it to this: $playerid = $cgi->getValue('playerid'); if( isset( $playerid ) ) Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 3, 2012 Author Share Posted May 3, 2012 changed it into: if( isset( $cgi->getValue['playerid'] ) ) according to the php manual i need to use [] instead of () for isset and empty. but then when i select 2 names (yes it loads without errors) it gives: No details found, please try again later this means the array is now empty I think? With your suggestion: replace $players_added = ''; if( isset( $cgi->getValue['playerid'] ) ) with $playerid = $cgi->getValue('playerid'); if( isset( $playerid ) ) when i load the page, even before i selected any names the follow appears above the selection box: Warning: implode(): Invalid arguments passed in httpd.www/poker/pokeradmin/players-to-tournaments.php on line 60 The player(s): have been assigned to the poker tournament. line 60 holds $player_list = implode( ',', $cgi->getValue('playerid') ); Quote Link to comment Share on other sites More sharing options...
creata.physics Posted May 3, 2012 Share Posted May 3, 2012 Try what I said in my post before this and see how that turns out. Your html for displaying the success messages( the message saying what users have been added) still displays. Previously I set it to only display if the playerid post data was submitted along with the form. So we are trying to get that message to show only when you submit the form. You need to understand the logic of your script and how to manipulate each function you have properly. If $cgi->getValue returns post data value, then you need to understand when, where, why and how to use it. Anyway, if what I posted in the post before yours does not work, then go ahead and post your full code once more. It would benefit you 100% more if you completely understood the code you use. Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 3, 2012 Author Share Posted May 3, 2012 yes i tried but it doesnt fire off correcly indeed like you concluded since the success message fires even before the submit taken place now with error obviously. Im trying to grasp the concept but its hard for me. just finished 5 day course of SQL and am now trying to learn PHP but its hard (but fun!), please bare with me in my ignorance full dump with implemented changes suggested earlier: <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournamnet League Solution</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../includes/style.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { foreach($cgi->getValue('playerid') as $player_id) { $result = mysql_query("SELECT playerid FROM {$score_table} WHERE playerid = '". $sql->quote( $player_id ) ."' AND tournamentid = '" . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "'") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $player_id ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); } } } $playerid = $cgi->getValue('playerid'); if( isset( $playerid ) ) { $player_list = implode( ',', $cgi->getValue('playerid') ); $players_added = "<p align='center' class='red'>The player(s): <strong>$player_list</strong> have been assigned to the poker tournament.</p>";} ?> <br> <?php echo $players_added; ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid[]" selected multiple="multiple" size="6"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?> UPDATE: put the <br> <?php echo $players_added; ?> AFTER the POST now and then it doesnt fire before the submit, however the error still shows on loading the page: Warning: implode(): Invalid arguments passed in /httpd.www/poker/pokeradmin/players-to-tournaments.php on line 60 Quote Link to comment Share on other sites More sharing options...
creata.physics Posted May 3, 2012 Share Posted May 3, 2012 this will work <?php include "../includes/config.php"; if (isset($_COOKIE["ValidUserAdmin"])) { require ( "../includes/CGI.php" ); require ( "../includes/SQL.php" ); $cgi = new CGI (); $sql = new SQL ( $DBusername, $DBpassword, $server, $database ); if ( ! $sql->isConnected () ) { die ( $DatabaseError ); } ?> <html> <head> <title>PokerMax Poker League :: The Poker Tournamnet League Solution</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <link href="../includes/style.css" rel="stylesheet" type="text/css" /> </head> <body bgcolor="#F4F4F4"> <?PHP include ("header.php"); ?> <table width="100%" cellpadding="5" cellspacing="0" border="0"> <tr> <td valign="top" bgcolor="ghostwhite" class="menu"><?PHP include ("leftmenu.php"); ?></td> <td bgcolor="#FFFFFF"> </td> <td valign="top" align="left" width="100%" bgcolor="#000000"><h1><br /> <img src="images/home.gif" width="25" height="25" /> PokerMax Poker League :: <font color="#CC0000">Assign Players to Tournaments</font></h1> <br /> <p>If you are running multiple tournaments on your website, this feature will allow you to assign any of your players to tournaments which you are running.</p> <?php if ( $cgi->getValue ( "op" ) == "AssignPlayer" ) { foreach($cgi->getValue('playerid') as $player_id) { $player_store[] = $player_id; $result = mysql_query("SELECT playerid FROM {$score_table} WHERE playerid = '". $sql->quote( $player_id ) ."' AND tournamentid = '" . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . "'") or die ("$DatabaseError"); $chkd_email = mysql_numrows($result); if ($chkd_email != "") { print "<p class=\"red\"><strong>The Player has already been assigned to this tournament</strong></p>"; } else { mysql_query("INSERT INTO ".$score_table." VALUES ( '', " . $sql->quote ( $player_id ) . ", " . $sql->quote ( $cgi->getValue ( "tournamentid" ) ) . ", '0', '$dateadded' )") or die ("$DatabaseError"); } } } if( isset( $player_store ) and is_array( $player_store ) ) { $player_list = implode( ',', $player_store ); $players_added = "<p align='center' class='red'>The player(s): <strong>$player_list</strong> have been assigned to the poker tournament.</p>";} ?> <br> <?php echo $players_added; ?> <form method="post"> <input name="op" type="hidden" value="AssignPlayer"> <select name="playerid[]" selected multiple="multiple" size="6"> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $player_table . " ORDER BY playerid ASC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "playerid" ] ); ?> - <?php echo $cgi->htmlEncode ( $row [ "name" ] ); ?> </option> <?php } ?> </select> <em>and assign to the tournament =></em> <select name="tournamentid" size="1"> <option value="">Select Tournament ....</option> <?PHP $rows = $sql->execute ( "SELECT * FROM " . $tournament_table . " ORDER BY id DESC", SQL_RETURN_ASSOC ); for ( $i = 0; $i < sizeof ( $rows ); ++$i ) { $row = $rows [ $i ]; ?> <option value="<?php echo $cgi->htmlEncode ( $row [ "tournamentid" ] ); ?>"> <?php echo $cgi->htmlEncode ( $row [ "tournament_name" ] ); ?> </option> <?php } ?> </select> <input type="submit" value="Assign Player" ONCLICK="return confirm('Are you sure you want to add this player to the tournament?');" /> </form> <br /></td> </tr> </table> <?PHP include ("footer.php"); ?> </body> </html> <?php } else { header("Location: index.php"); exit; } ?> I've made a small script to accomplish this same goal in a simplified manor. <?php if( isset( $_POST['process'] ) ) { foreach( $_POST['playerid'] as $player ) { $player_list[] = $player; mysql_query("insert into table( key ) values ('$player')"); } } if( isset( $player_list ) and is_array( $player_list ) ) { echo implode(',', $player_list) . " were chosen"; } ?> <form action="" method="post"> <select multiple="multiple" name="playerid[]"> <option value="Bob">Bob</option> <option value="Matt">Matt</option> <option value="Tim">Tim</option> </select> <input type="submit" name="process"> </form> It would benefit you if you looked at the second code first and understand exactly how it works. you'd then be able to integrate the same functionality into your current script on your own and be able to debug it a lot easier since you can backtrack and see where you went wrong. Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 3, 2012 Author Share Posted May 3, 2012 no errors on loading page with the first suggestion (i didnt implement your suggesions yet on the second codeblock since i first want to get it working as is). however: No details found, please try again later array empty in your code? Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 3, 2012 Author Share Posted May 3, 2012 echo $player_store . '<br/>'; gives no names back so indeed the array isnt functioning. If i put the echo higher in the code on Player_id i get only the first selected name back. so indeed the array isnt picking up the names as it should. Quote Link to comment Share on other sites More sharing options...
Jorn Posted May 6, 2012 Author Share Posted May 6, 2012 well I can understand you guys are done investing time in this project And the main goal is accoplished! I can add multiple players to a tournament in one go! So the checking for double isnt working and I get the message displayed multiple times but thats no big deal really. Special thanks to Creata.Physics for his huge help and great examples, sure learned alot this week Bought a PHP book today so going to study the matter some more, who knows I might someday be able to help others here! anyway thanks again! 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.