Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

seperating PHP and HTML 1

Status
Not open for further replies.

StuartBombay

Programmer
Feb 11, 2008
56
US
I have this page, but when it runs on the form with the drop-down there is an error that states it can't fird $name on line 41, and on the results page is states it can't find the variable $display_block on line 50.
I'm sure this is a case of I missed keeping the HTML from the PHP somewhere. Can anyone see where I went wrong?

Code:
<?php
$page_title = 'PPS Site Summary - Employee Information';
include('header.html');
include('functions/form_functions.inc');
require('../../includes/configdb.inc');
require('../../includes/opendb.inc');
global $conn;
if (!$_POST)  {
//if a selection has not been made, then show the selection form with dropdown
	$display_block = "<h2>Who is...";
	$display_block .= drop_down('person', 'username', 'full', 'v_people_detail', '', 'last');
	$display_block .= "</h2>";

} else if ($_POST) {  
	
//if  a selection has been made, display info
	if ($_POST["sel_id"] == "") {
		header("Who is who_is.php");
	exit;
	} //end if
//get person info
	$query = "SELECT * from v_people_detail where username = 
		'".$_POST["sel_id"]."'";
	$get_person_rs = mysqli_query($conn, $query)
			or die(mysqli_error($conn));
	while ($person_info = mysqli_fetch_array($get_person_rs)) {
		$name = stripslashes($person_info['full']);
		$user = stripslashes($person_info['username']);
		$emlpid = stripslashes($person_info['emplid']);
		$progname = stripslashes($person_info['progname']);
		$locname = stripslashes($person_info['locname']);
		$phone = stripslashes($person_info['phone']);
		$jobtitle = stripslashes($person_info['jobtitle']);
	} //end while
	$display_block .=" <li><h3>$name</h3>  <a href='mailto:".$user."@pps.k12.or.us'> (Email ".$name.")</a>
										<li>Department: $progname
										<li>Located at: $locname
										<li>Location phone: $phone
										<li>Title: $jobtitle
										</li></ul>";
	$display_block .= "<br/><br/>";

$display_block .= "<br/><br/><br/>
<a href=\"".$_SERVER["PHP_SELF"]."\">Select another person</a></p>";
} //end if POST sel_id
//close connection to database
require('../../includes/closedb.inc')
?>
<html>
<head>
<?php echo $page_title = $name; ?>
</head>
<body>
<?php echo $display_block; 
include('footer.html');?>
</body>
</html>

There are functions and headers that aren't shown in this code, despite that I hope my error jumps out at someone!

Thanks -
 
You are likely getting something along the lines of:
Notice Undefined Variable $display_block in....
Code:
 } //end while
    $display_block .=" <li><h3>$name</h3>  <a href='mailto:".$user."@pps.k12.or.us'> (Email ".$name.")</a>
There's nothing previous to that usage that initializes $display_block. So Trying to concatenate to an uninitialized variable will issue the Notice.

Adding a $display_block=""; about here should get rid of the notice:

Code:
else if ($_POST) {  
[red]$display_block="";[/red]    
//if  a selection has been made, display info
    if ($_POST["sel_id"] == "") {
        header("Who is who_is.php");

As for the $name variable: I can;t see anything that wold cause it. Can you point out the line that it refers to in the Notice. In other words in your code which is line 41.





----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Thanks vacunita, $display_block is initialized on line 8.

Code:
<?php
$page_title = 'PPS Site Summary - Employee Information';
include('header.html');
include('functions/form_functions.inc');
require('../../includes/configdb.inc');
require('../../includes/opendb.inc');
global $conn;
if (!$_POST)  {
//if a selection has not been made, then show the selection form with dropdown
	$display_block = "<h2>Who is...";

but maybe one bit of display_block is outside where it needs to be? I've just begun with PHP, and am realizing a firm base in HTML would have been helpful. I'm not always sure where I'm starting one and leaving off the other.

thanks-
 
You're declaring display_block inside an if statement. if($_POST), it isn't declared. Try declaring all your variables at the top, right after your includes and requires.
Also it looks like
Code:
$display_block .=" <li><h3>$name</h3>  <a href='mailto:".$user."@pps.k12.or.us'> (Email ".$name.")</a>
                                        <li>Department: $progname
                                        <li>Located at: $locname
                                        <li>Location phone: $phone
                                        <li>Title: $jobtitle
                                        </li></ul>";
should probably be inside the while loop above it. Otherwise it'll only print the last one, and it'll give you errors if the while loop iterates 0 times.

-----------------------------------------
I cannot be bought. Find leasing information at
 
Thank you - I had a feeling it had something to do with placement.
 
jaxtell got it right, for both.

As he said if you declare a variable inside an If block then it will only be declared if the If block fires. However you are using it in the event the If block does not fire, so it never really gets declared.



----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top