fife Posted February 15, 2011 Share Posted February 15, 2011 hello. On my function page I have this function. function GetClub($clubs) { $qFindClub = "SELECT * FROM clubs WHERE memberID = '$clubs'"; $rFindClub = mysql_query($qFindClub); $Club = mysql_fetch_array($rFindClub); return $Club; } now when I feed it the variable $myID. If I try to echo say the club name $Clubs = GetClub($myID); echo $Clubs['name']; Nothing happens as its not working properly. Can anybody see what I have done wrong? Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/ Share on other sites More sharing options...
kenrbnsn Posted February 15, 2011 Share Posted February 15, 2011 Try changing your code to return any errors: <?php function GetClub($clubs) { $qFindClub = "SELECT * FROM clubs WHERE memberID = '$clubs'"; $rFindClub = mysql_query($qFindClub) or return(array(false,'query'=>$query,'error'=>mysql_error());; $Club = mysql_fetch_array($rFindClub); return array(true,'results'=>$Club); } To use the above code: <?php $Clubs = GetClub($myID); if (!$Clubs[0]) { echo '<pre>' . print_r($Clubs,true) . '</pre>'; } else { echo '<pre>' . print_r($Clubs['results'],true) . '</pre>'; } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174559 Share on other sites More sharing options...
fife Posted February 15, 2011 Author Share Posted February 15, 2011 Ken that code echos this on the server [Tue Feb 15 16:11:21 2011] [error] [client 90.198.47.133] PHP Parse error: syntax error, unexpected T_RETURN in /home/sites/site/functions.php on line 30, referer: http:/site.php?new_club=6620d5b156ae8c2ddf298249e The line it says is wrong is $rFindClub = mysql_query($qFindClub) or return(array(false,'query'=>$query,'error'=>mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174567 Share on other sites More sharing options...
kenrbnsn Posted February 15, 2011 Share Posted February 15, 2011 Try this instead: <?php function GetClub($clubs) { $qFindClub = "SELECT * FROM clubs WHERE memberID = '$clubs'"; $rFindClub = mysql_query($qFindClub); if (!$rFindClub) { return(array(false,'query'=>$query,'error'=>mysql_error())); } else { $Club = mysql_fetch_array($rFindClub); return array(true,'results'=>$Club); } } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174579 Share on other sites More sharing options...
fife Posted February 15, 2011 Author Share Posted February 15, 2011 Ok that seems to work in someway. I prints a list of the selected club Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174588 Share on other sites More sharing options...
kenrbnsn Posted February 15, 2011 Share Posted February 15, 2011 Please post what it prints. From that we can tell you how to reference what you're looking for. Ken Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174596 Share on other sites More sharing options...
fife Posted February 15, 2011 Author Share Posted February 15, 2011 Array ( [0] => 9 [clubID] => 9 [1] => 15 [memberID] => 15 an so on to the end of the table. ) What im looking for is from the being able to echo say the clubID by typing echo $Clubs['clubID']; Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174615 Share on other sites More sharing options...
kenrbnsn Posted February 15, 2011 Share Posted February 15, 2011 Use <?php $tmp = GetClub($myID); if (!$tmp[0]) { echo '<pre>' . print_r($tmp,true) . '</pre>'; } else { $Clubs = $tmp['results']; // // put the rest of your code here // } ?> Ken Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174616 Share on other sites More sharing options...
fife Posted February 15, 2011 Author Share Posted February 15, 2011 Ok ill post the whole pages as is so far to show you what Ive got. That last piece of code doesn't do it either. <?php include('../Connections/connect.php'); include('../functions.php'); session_start(); //calls to functions $User = GetUser($_SESSION['Username']); $Clubs = GetClub($User['memberID']); $tmp = GetClub($myID); if (!$tmp[0]) { echo '<pre>' . print_r($tmp,true) . '</pre>'; } else { $Clubs = $tmp['results']; } //if (!$Clubs[0]) { // echo '<pre>' . print_r($Clubs,true) . '</pre>'; //} else { // echo '<pre>' . print_r($Clubs['results'],true) . '</pre>'; //} $randomKey = getUniqueCode2(25); $newCatKey = getUniqueCode2(20); ?> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Create a new club account here on</title> <link href="/members/logged.css" rel="stylesheet" type="text/css" /> </head> <body> <div id="wrapper"> <div id="head"> <div align="left"><a href="index.php"><img src="../images/logo.png" width="410" height="125" border="0" /></a></div> </div> <div id="horiz_navigation"></div> <div id="vert_navigation"> </div> <div id="content"> <form action="" method="post" name="insert_club" id="insert_club"> <table width="400" id="insert_club_tbl" > <tr valign="baseline"> <td width="176" valign="top" nowrap="nowrap">Club Name:</td> <td width="752" valign="top"><div align="left"> <input type="text" name="name" value="<?php echo $Clubs['clubID'] ;?>" size="32" /> </div></td> </tr> <tr valign="baseline"> <td valign="top" nowrap="nowrap"> </td> <td valign="top"><div align="left"> <input type="submit" id="insert_club" name="insert_club" value="Insert record" /> </div></td> </tr> </table> </form> </div> <?php include('../footer.php'); ?> </div> </body> </html> I have checked and the $User['memberID']; does hold the actual ID. Quote Link to comment https://forums.phpfreaks.com/topic/227760-function-not-working/#findComment-1174622 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.