Dosent execute code ?

Hi!

Have this code:

FILE ---> golfklubb_form.php
<?php

$newsletters = $newsletter->get_golfclubs($db);

//echo "ID GOLF 2 : ".$golfclub_id;
//die();
?>
<!--  Hate tables but need them -->
<h2><span>Legg til ny klubb</span></h2>
  <table cellpadding="5">
	
		<tr>
			<td>
			  <label>Golf Klubb</label>
			</td>
			<td>
				<div class="form_field"><select name="mem_golfclub4" id="golfclub">
			
					<?php 
					
					foreach($newsletters as $newsletter){
						?>
						<option value="<?php echo $newsletter['golf_id'];?>"><?php echo $newsletter['namegolf'];?></option>
						<?php
					}
					?>
				</select>
				
				</div>
			</td>
		</tr>
		<tr>
			<td>
				<label>Brukernavn</label>
			</td>
			<td>
				<div class="form_field"><input type="text" name="mem_first_name" id="first_name" value="<?php echo $member_data['first_name'];?>"></div>
			</td>
		</tr>
		<tr>
			<td>
				<label>Passord</label>
			</td>
			<td>
				<div class="form_field"><input type="text" name="mem_last_name" id="last_name" value="<?php echo $member_data['last_name'];?>"></div>
			</td>
		</tr>
	<tr>
			<td width="200px;">
				<label>Bounce Email</label>
			</td>
			<td width="300px;">
				<div class="form_field"><input type="text" name="mem_email_bounce" id="bouemail" value="<?php echo $member_data['email'];?>"></div>
			</td>
		</tr>
		
		<tr>
			<td width="200px;">
				<label>Fra Email</label>
			</td>
			<td width="300px;">
				<div class="form_field"><input type="text" name="mem_email_fra" id="fraemail" value="<?php echo $member_data['email'];?>"></div>
			</td>
		</tr>
		
		<tr>
			<td>
				
			</td>
			<td>
				<div class="buttons">
				 <input type="submit" name="save_golfclub" value="Lagre klubb" class="button">
		    </div>
		 	</td>
		</tr>
		
	</table>
	
	<h2><span>Registrerte golfklubber 44:</span></h2>

<div class="box">
	<table cellpadding="5" class="stats">
		<tr>
			<th>Golf klubb</th>
			<th>Registrert dato</th>
			<th>Brukernavn</th>
			<th>Passord</th>
			<th>Status</th>
		</tr>					
				<?php
		$newsletters = $newsletter->get_golfcustomers($db);
		
		foreach($newsletters as $n){ 
			?>
		<tr>
			<td>
				<?php echo $n['namegolfclub'];?>
			</td>
			<td>
				<?php echo $n['join_date'];?>
			</td>
			
			<td>
				<?php echo $n['Username'];?>
			</td>
			
			<td>
				<?php echo $n['Password'];?>
			</td>

			<td>
				<?php echo $n['status'];?>
			</td>
		</tr>
		<?php } ?>
		
	</table>
</div>

Open in new window






FILE ----> golfclubb.php
<?php
/**
 * Author: Tor Erik Berg
 * Version: 0.98 
 * 
**/
error_reporting(E_ALL);

if($_REQUEST['save_golfclub'] && $_REQUEST['mem_first_name'] && $_REQUEST['mem_last_name']){
	
	session_start();
	//$golfclub_id2=(int)$_SESSION['logoclub'];
    //$_SESSION['logoclub']=14;
	
	$golfklubnavn = $newsletter->get_golfclubname($db,$_REQUEST['mem_golfclub4']);
	$fields = array(
		"brukernavn"=>htmlspecialchars($_REQUEST['mem_first_name']),
		"passord"=>htmlspecialchars($_REQUEST['mem_last_name']),
		"emailbounce"=>htmlspecialchars($_REQUEST['mem_email_bounce']),
		"emailfra"=>htmlspecialchars($_REQUEST['mem_email_fra']),
		"golfclub"=>htmlspecialchars($_REQUEST['mem_golfclub4']),
		"navnklubb"=>htmlspecialchars($golfklubnavn),
	);
	$message="START : ";
	
	//echo "<script type='text/javascript'>alert('$message');</script>";
	$golf_id = $newsletter->save_golfclub($db,$fields);
	
	if($golf_id){
		
        ob_end_clean();
	    header("Location: index.php?p=golfklubb");
		exit;
	}
	
}


?>

<form action="" method="post" id="create_form">
<input type="hidden" name="member_id" value="new">
<input type="hidden" name="save" value="true">

<div class="box">
	<?php
         	
	    include("golfklubb_form.php"); 
		
	 ?>
</div>

</form>

Open in new window



AND the function

public function get_golfcustomers($db){
	if(!$db)$db = db_connect();
	$sql = "SELECT * FROM `"._DB_PREFIX."customergolf`";
	$sql .= " ORDER BY namegolfclub";
	
	return query($sql,$db);
}

Open in new window



The problem is that this code dosent execute at all ?

				<?php
		$newsletters = $newsletter->get_golfcustomers($db);
		
		foreach($newsletters as $n){ 
			?>
		<tr>
			<td>
				<?php echo $n['namegolfclub'];?>
			</td>
			<td>
				<?php echo $n['join_date'];?>
			</td>
			
			<td>
				<?php echo $n['Username'];?>
			</td>
			
			<td>
				<?php echo $n['Password'];?>
			</td>

			<td>
				<?php echo $n['status'];?>
			</td>
		</tr>
		<?php } ?>

Open in new window


What is the problem here ?
LVL 2
team2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
This is likely a data-dependent error, and that means we need to be able to see the data (not just the code) in order to understand what is going wrong.  Data-dependent errors require some processes to uncover and correct the problems.

Let's start by adding error_reporting(E_ALL) to the top of your PHP scripts (all of them) and correct any Notice messages that appear.  The elevated error_reporting() will help you find a great many things that are potentially troublesome.

Next, use var_dump() to print out the contents of your dependencies.  "Dependencies" are the things that your script depends on in order to function correctly.  Consider these statements:
<?php
$newsletters = $newsletter->get_golfcustomers($db);
foreach($newsletters as $n){ 

Open in new window

In the first line, $db is a dependency because the $newsletter object depends on $db and uses it as input to the get_golfcustomers() method.  In the second line $newsletters is a dependency because the foreach() iterator depends on it to create the variable $n.  Follow this process for each of the variables that might be in play in the logic of your script.

Finally, consider this line of code:
return query($sql,$db);

Open in new window

How do you know that the $sql query found anything, or that it even ran at all?  SQL functions are not trustworthy black boxes - they can and will fail for a variety of reasons (some that are even outside of your control) and unless you test the results for success, you will never be able to trust the results.  This article is worth reading because it shows you how to run queries and test for success.  And it shows how to visualize the error conditions when a failure occurs.  

Once you know about the data you're working with, it will be easy to find the right code to handle this data, so let's do these things, see the outputs from var_dump() and then we can begin debugging.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Mark BradyPrincipal Data EngineerCommented:
Ray comment makes a lot of sense. Where in your code are you including the classes that you are using ($db and $newsletters)? The file that those classes are stored in need to be included in the file that you use them in. In your case, I would make them a requirement:

require_once 'path_to_your_class_file/newsletters.php'; // or whateve the filename is

Then they need to be instantiated with whatever arguments they require. For example:

$newsletters = new NewsLetters();

Only then can you start using them in your code.

If you take Ray's advice and enable error reporting and run your script you will see what the problem(s) are and can then fix them.
0
team2005Author Commented:
Hi!

Put on top of every file used -> error_reporting(E_ALL);

But it dosent display any errors ?
0
Ray PaseurCommented:
OK, error_reporting() was Step #1.

Here is Step #2:
Next, use var_dump() to print out the contents of your dependencies.
0
team2005Author Commented:
tHANKS
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.