Jump to content

[SOLVED] if (isset) not working


whiskedaway

Recommended Posts

I think I've made a silly mistake somewhere, but I can't find it, so any help would be appreciated! I've used if (isset) in other parts of my website and it works fine, but I can't get it working here.

 

Basically, the PHP is meant to run a query on my database and return $staffID, $name, $address and $phone, and then is meant to be displayed in a table that is located in stafflook.inc.

 

Code snippets:

$cxn = mysqli_connect($host, $user, $password, $dbname) 
               or die ("Connection failed.");

    $sql = "SELECT staffID, name, address, phone FROM Staff
	       WHERE staffID = '$_POST[staffID]'";	
    $result = mysqli_query($cxn, $sql)
                  or die ("Couldn't execute query.");
        $rowname = mysqli_fetch_assoc($result);
        extract ($rowname);

	$echoName = "<tr><td><strong>ID:</strong></td><td>$name</td></tr>";
	$echoID = "<tr><td><strong>ID:</strong></td><td>$staffID</td></tr>";
	$echoAddress = "<tr><td><strong>ID:</strong></td><td>$address</td></tr>";
	$echoPhone = "<tr><td><strong>ID:</strong></td><td>$phone</td></tr>";

	include("stafflook.inc");

 

stafflook.inc:

<table width="250" border="0" align="center" cellpadding="2" cellspacing="2">
<?php
    if (isset($echoID)) { echo "$echoID";}
if (isset($echoName)) { echo "$echoName";}
if (isset($echoAddress)) { echo "$echoAddress";}
if (isset($echoPhone)) { echo "$echoPhone";}
?>
</table>

 

If someone can see where I've made a mistake, it'd be greatly appreciated.

Link to comment
Share on other sites

I'm actually getting no output at all, even with putting print_r($array);. I would assume that opening the page I'd get no output, but when I run the query, it should work.

 

Here's the full code for both of the pages, hopefully it might be something that's not in the first code snippets:

<?php

    session_start();

    if (@$_SESSION['auth'] != "yes") {

        header("Location: management.php");
        exit();
    }
	include("credentials.inc");

switch (@$_POST['do']) {

    case "search":

    $cxn = mysqli_connect($host, $user, $password, $dbname) 
               or die ("Connection failed.");

    $sql = "SELECT staffID, name, address, phone FROM Staff
	       WHERE staffID = '$_POST[staffID]'";	
    $result = mysqli_query($cxn, $sql)
                  or die ("Couldn't execute query.");
        $rowname = mysqli_fetch_assoc($result);
        extract ($rowname);

	$echoName = "<tr><td><strong>Name:</strong></td><td>$name</td></tr>";
	$echoID = "<tr><td><strong>ID:</strong></td><td>$staffID</td></tr>";
	$echoAddress = "<tr><td><strong>Address:</strong></td><td>$address</td></tr>";
	$echoPhone = "<tr><td><strong>Phone:</strong></td><td>$phone</td></tr>";

	print_r($array);

	include("stafflook.inc");

        break;

        default:

        include("stafflook.inc");

}
?>

 

stafflook.inc

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Adelaide Books</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>

<body>
<div id="body">
<table id="main" cellspacing="0px">
<tr><td id="logo" colspan="3">
<img src="images/logo.gif" alt="Adelaide Books"/></td>
<td class="space"> </td>
<td class="right"> </td></tr>
<tr><td class="left"> </td>
<td class="space">
<form action="stafflookup.php" method="POST">
Staff ID: <input type="text" name="staffID" size="25" value=""><br/>
<input type="submit" name="Search" value="Search"></form></td>
<td id="text">
 <br/> <br/> <br/>

<table width="250" border="0" align="center" cellpadding="2" cellspacing="2">
<?php
    if (isset($echoID)) { echo "$echoID";}
if (isset($echoName)) { echo "$echoName";}
if (isset($echoAddress)) { echo "$echoAddress";}
if (isset($echoPhone)) { echo "$echoPhone";}
?>
<tr><td width="75px" align="right"> </td><td> </td></tr>
</table>
 <br/> <br/> <br/> <br/><a href="management2.php"><img src="images/back.gif" alt="Back" border="0" /></a></td>
<td class="space"> </td>
<td class="right"> </td></tr>
</table>
</div>
</body>
</html>

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.