Jump to content

Recommended Posts

Basically i have a few types of these pages where i can just change out the field names and somewhere along the way I went astray and now the pages will not show up at all. I want to say it's as simple as a missing ; or a misspelling of syntax but for the life of me i can not find it. I will post the code but it's not fair to expect anyone to read it all since there is so much, but is there a good debugging way to find out where my problem might exist. Usually i will get t_else errors on line etc...and those are easy to diagnose, but when the page is blank...its finding a needle in the haystack. (Code below) thanks again.

<html> 
<head> 
<title>Manage Coordinator Log</title> 
</head> 
<body> 
<?php 
/************************************************************************* 
               control code for application 
*************************************************************************/ 

//submit button was pressed so call the process form function 
if (isset($_POST['submit'])) 
{ 
  process_form(); 
  die(); 
}//end if 


//call the get_data function 
if (isset($_GET['id'])) 
{ 
  get_data(); 
}//endif 


//nothing chosen so list the dma's 
if ((empty($_POST))&&(empty($_GET))) 
{ 
  list_users(); 
  die(); 
}//end if 


//request to add a new contact so call the show_form function 
if ((isset($_GET['action']))&&($_GET['action']=='add')) 
{ 
  show_form(); 
}//endif 



/************************************************************************* 
               get the data for an individual contact 
*************************************************************************/ 

function get_data() 
{ 
    //validate the id has been passed at that it is a number 
    if ((empty($_GET['id']))||(is_nan($_GET['id']))) 
    { 
        //there was a problem so list the users again 
      list_users(); 
      //kill the script 
      die(); 
    }else{ 
      //all is ok and assign the data to a local variable 
      $id = $_GET['id']; 
    }//end if 
$sql = "select * from coordinator where id = {$id} order by KVCode;"; 
    $result = conn($sql); 
    if (mysql_num_rows($result)==1){ 
      //call the form and pass it the handle to the resultset 
      show_form($result); 
    }else{ 
      $msg = "No data found for selected Coordinator"; 
      confirm($msg); 
      //call the list users function 
      list_users(); 
    }//end if  
}//end function 


/************************************************************************* 
               show the input / edit form 
*************************************************************************/ 
function show_form($handle='',$data='') 
{ 
  //$handle is the link to the resultset, the ='' means that the handle can be empty / null so if nothing is picked it won't blow up 
  
  //set default values 
  $KVCode  = ''; 
  $FullName  = ''; 
  $PhoneNumber  = ''; 
  $Email  = ''; 
  $AccessLevel  = ''; 
  $Commission  = ''; 
  $ReportsTo  = ''; 
  $id      = ''; 
  $value      = 'Add';  //submit button value 
  $action     = 'add';  //default form action is to add a new dma/station to db 

  //set the action based on what the user wants to do 
  if ($handle) 
  { 
    //set form values for button and action 
    $action = "edit"; 
    $value  = "Update"; 
    
    //get the values from the db resultset 
    $row = mysql_fetch_array($handle); 
    $KVCode  = $row['KVCode']; 
    $FullName  = $row['FullName']; 
    $PhoneNumber  = $row['PhoneNumber']; 
    $Email  = $row['Email']; 
    $AccessLevel  = $row['AccessLevel']; 
    $Commission  = $row['Commission']; 
    $ReportsTo  = $row['ReportsTo']; 
    $id          = $row['id']; 
  
  }//end if 
  
  //error handling from the processing form function 
  if($data != '') 
  { 
    $elements = explode("|",$data); 
        $KVCode     = $elements[0]; 
        $FullName     = $elements[1]; 
        $PhoneNumber     = $elements[2]; 
        $Email     = $elements[3]; 
        $AccessLevel     = $elements[4]; 
        $Commission     = $elements[5]; 
        $ReportsTo     = $elements[6]; 
        $id             = $elements[7]; 
  } 
?> 

<body> 

<?php 
include "smsinclude.php"; 
echo $navigation; ?>
<p style="font-size:18px; font-weight:bold;">Manage Coordinators Log</p>
<form name="form1" method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>?action=<?php  echo $action?>"> 
<table width="700" bgcolor="ffffff" cellpadding="5" cellpsacing="0" border="1" bordercolor="#000000">
<tr>
	<td><input type="hidden" value="<?php echo $id?>" name="id">
		<table width="700" cellpadding="0" cellpsacing="0" border="0" bordercolor="#000000">
			<tr>
				<td align="left" width="180">KV Code</td>
				<td width="320" align="left"><input type="text" name="KVCode" size="15" value="<?php echo $KVCode ?>"></td>
				<td align="left" width="200">ex) ccdhc6</td>
			</tr>
			<tr>
				<td align="left" width="180">Full Name</td>
				<td width="320" align="left"><input type="text" name="FullName" size="15" value="<?php echo $FullName ?>"></td>
				<td align="left" width="200">ex) David Coombs </td>
			</tr>
			<tr>
				<td align="left" width="180">Phone Number</td>
				<td width="320" align="left"><input type="text" name="PhoneNumber" size="40" value="<?php echo $PhoneNumber ?>"></td>
				<td align="left" width="200">ex) 765-473-3396 </td>
			</tr>
		<tr>
				<td align="left" width="180">Email</td>
				<td width="320" align="left"><input type="text" name="Email" size="40" value="<?php echo $Email ?>"></td>
				<td align="left" width="200">ex) dcoombs@kindervision.org </td>
			</tr>                
                
			<tr>
				<td align="left" width="180">Access Level</td>
				<td width="320" align="left"><input type="text" name="AccessLevel" size="40" value="<?php echo $AccessLevel ?>"></td>
				<td align="left" width="200">ex) 1 is NC, 2 is RC, 3 is CC </td>
			</tr>
		<tr>
				<td align="left" width="180">Commission Percentage</td>
				<td width="320" align="left"><input type="text" name="Commission" size="40" value="<?php echo $Commission ?>"></td>
				<td align="left" width="200">ex) 25% leave out % sign </td>
			</tr>
		<tr>
				<td align="left" width="180">Reports To:</td>
				<td width="320" align="left"><input type="text" name="ReportsTo" size="40" value="<?php echo $ReportsTo ?>"></td>
				<td align="left" width="200">ex) Andy Mars KVRC</td>
			</tr>                
                <tr>
				<td colspan="3">
				<p align="center"><input name="submit" type="submit" value="<?php echo $value ?>"> <input name="reset" type="reset" value="Clear Form"></p>
				</td>
			</tr>
		</table>
	</td>
</tr>
</table><br />
</form>
<?php echo $navigation2; ?>

<? 
}//end function 


/************************************************************************* 
               list all the DMA/Stations in the db 
*************************************************************************/ 
function list_users() 
{ 
    $y = 0; //counter 
    $sql = "select * from coordinator order by KVCode;";  
    $result = conn($sql); 

include "smsinclude.php"; 


  echo "<table width=\"700\" cellpadding=\"0\" cellspacing=\"0\"> 
        	<tr><td colspan=\"2\" style=\"font-size:18px; font-weight:bold;\">Manage Coordinator Log</td></tr> 
        	<tr>
			<td valign=\"top\"><br><a href='".$_SERVER['PHP_SELF']."?action=add'>Add a new Coordinator</a></td>
			<td valign=\"top\"><br>$navigation</td>
		</tr>
	</table>
	<table width=\"1060\" cellpadding=\"5\" cellspacing=\"0\">
		<tr>
			<td width=\"80\"><b><u>KV Code</u></b></td>
			<td width=\"150\"><b><u>Full Name</u></b></td>
			<td width=\"150\"><b><u>Phone Number</u></b></td>
			<td width=\"150\"><b><u>Email</u></b></td>
			<td width=\"150\"><b><u>Access Level</u></b></td>
			<td width=\"150\"><b><u>Commission Percentage</u></b></td>
			<td width=\"150\"><b><u>Reports To</u></b></td>
			<td width=\"80\"><b><u>Delete</u></b></td></tr>";
  
         
     if (mysql_num_rows($result)){ 
      //show a list of kids with name as a link to the prepopulated form with their data in it 
      while($rows = mysql_fetch_array($result)){ 
        
        //change row background color 
        (($y % 2) == 0) ? $bgcolor = "#F8F7F2" : $bgcolor=" #FFFFFF"; 
        
        //build strings to make life easier 
        $KVCode = $rows['KVCode']; 
        $FullName = $rows['FullName']; 
        $PhoneNumber = $rows['PhoneNumber']; 
        $Email = $rows['Email']; 
        $AccessLevel = $rows['AccessLevel']; 
        $Commission = $rows['Commission']; 
        $ReportsTo = $rows['ReportsTo']; 
        $id = $rows['id']; 
	$field_data = "coordinator";	

        //convert status to readable string from 1 or 0 
        ($status == 0) ? $status = "Available to contact" : $status = "Do not contact at present."; 
        
        //echo out the row 
        echo "<tr style='background-color:$bgcolor;'>
			<td valign=\"top\" width=\"80\" height=\"30\" valign=\"middle\"><a href='".$_SERVER['PHP_SELF']."?id=$id'>$KVCode</a></td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$FullName</td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$PhoneNumber</td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$Email</td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$AccessLevel</td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$Commission</td>
			<td valign=\"top\" height=\"30\" valign=\"middle\">$ReportsTo</td>
			<td width=\"80\" valign=\"top\" height=\"30\" valign=\"middle\"><a href='delete_record.php?id=$id&field_data=$field_data'>Delete</a></td><tr>"; 
        $y++;  //increment the counter 
      }//end while 
      echo "</table><br>$navigation2 <br><br>If you wish to print this page you must use Landscape Printing for best results"; 

  }else{ 
    //handle no results 
    echo "<tr><td colspan='9' align='center'><b>No data found.</b></td></tr>"; 
  }//endif 
} 


/************************************************************************* 
               add / update the contact's data 
*************************************************************************/ 
function process_form() 
{ 
  $KVCode  = ''; 
  $FullName  = ''; 
  $PhoneNumber  = ''; 
  $Email  = ''; 
  $AccessLevel  = ''; 
  $Commission  = ''; 
  $ReportsTo  = ''; 
  $id     = ''; 
  $action = ''; 
  $status = 0;    //default value 

  $KVCode  = @$_POST['KVCode']; 
  $FullName  = @$_POST['FullName'];  
  $PhoneNumber  = @$_POST['PhoneNumber']; 
  $Email  = @$_POST['Email'];  
  $AccessLevel  = @$_POST['AccessLevel']; 
  $Commission  = @$_POST['Commission'];  
  $ReportsTo  = @$_POST['ReportsTo']; 
  $id     = @$_POST['id'];          
  $action = @$_GET['action']; 
  $status = @$_POST['status']; 
  
  //if no status is set, defaults to 0 (allow contact) 
  if ($status == ''){$status = 0; } 
    
  if (($KVCode=='')||($FullName=='')||($PhoneNumber=='')||($Email=='')||($AccessLevel==''))||($Commission=='')||($ReportsTo=='')) 
  { 
    $msg = "Some data from the form was forgotten. Please fill in the entire form."; 
    confirm($msg); 
    $data = "$KVCode|$FullName|$PhoneNumber|$Email|$AccessLevel|$Commission|$ReportsTo|$id"; 
    show_form('',$data); 
    die(); 
  }//end if 
  
  //You could add some validation of the data ( I recommend it and its a great way to get your feet wet with php ) 

  if ($action == "add") 
  { 
    $sql = "insert into coordinator (KVCode, FullName, PhoneNumber, Email, AccessLevel, Commission, ReportsTo) values('{$KVCode}','{$FullName}','{$PhoneNumber}','{$Email}','{$AccessLevel}','{$Commission}','{$ReportsTo}');"; 
    $msg = "Record successfully added"; 
  }elseif($action=="edit"){ 
    $sql = "update coordinator set KVCode = '{$KVCode}', FullName = '{$FullName}', PhoneNumber = '{$PhoneNumber}', Email = '{$Email}', AccessLevel = '{$AccessLevel}', Commission = '{$Commission}', ReportsTo = '{$ReportsTo}' where id = {$id};"; 
    $msg = "Record successfully updated"; 
  } 
  $result = conn($sql); 
  if (mysql_errno()==0) 
  { 
    confirm($msg); 
    list_users(); 
  }else{ 
    $msg = "There was a problem adding the user to the database. Error is:".mysql_error(); 
    confirm($mag); 
  }//end if 
      
} 



/************************************************************************* 
               db connection function 
*************************************************************************/ 
function conn($sql) 
{    

$host = "localhost"; 
$user = "root"; 
$pass = "root"; 
$db     = "dreamteam_db"; 


    //echo "commnecing connection to local db<br>"; 
    
    if (!($conn=mysql_connect($host, $user, $pass)))  { 
        printf("error connecting to DB by user = $user and pwd=$pass"); 
        exit; 
    } 
    $db3=mysql_select_db($db,$conn) or die("Unable to connect to local database"); 

    $result = mysql_query($sql) or die ("Can't run query because ". mysql_error()); 
    
    return $result; 
    
}//end function      

/************************************************************************* 
               alert box popup confimation message function 
*************************************************************************/ 
function confirm($msg) 
{ 
  echo "<script langauge=\"javascript\">alert(\"".$msg."\");</script>"; 
}//end function 

?>

 

 

Link to comment
https://forums.phpfreaks.com/topic/156315-solved-page-is-empty-need-extra-eye/
Share on other sites

Code is never executed for a parse error so putting lines of code in to show parse errors won't ever be executed. The two settings must be set before the code is parsed.

 

There is at least one problem of mis-matched () in line 293 and you have one short open tag <? that should be changed to <?php

 

Edit: Recommending the use of short open tags will result in code that does get parsed on all servers and you will at some point in time need to go back and fix it. Most people don't like wasting time writing code twice.

Your a genious PFMABISMAD, it was the mismatch () sure enough.....when copy pasting the original file (since im reusing it) i copied to the end closing )) and left them in the middle....grrr.... Thanks so much everyone, all those before taught me a few things as well so I am very appreciative for that (shortcut for echoing a value, the debugging at the top) THANK YOU ALL!

Edit: Recommending the use of short open tags will result in code that does get parsed on all servers and you will at some point in time need to go back and fix it. Most people don't like wasting time writing code twice.

 

Thanks. Sorry for recommending bad practice. In all of the applications I handle it is always on my own dedicated servers. Never really had to worry about stuff not working. Thought something like that would be a good thing to have on all servers.

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.