Jump to content

function not working


fife

Recommended Posts

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?

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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());

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.