whiskedaway Posted November 7, 2009 Share Posted November 7, 2009 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 https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/ Share on other sites More sharing options...
rajivgonsalves Posted November 7, 2009 Share Posted November 7, 2009 code looks okay what is the output your getting ? Link to comment https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/#findComment-952986 Share on other sites More sharing options...
keldorn Posted November 7, 2009 Share Posted November 7, 2009 use print_r($array); fro the array to make sure you getting what you expect from the database. Link to comment https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/#findComment-953017 Share on other sites More sharing options...
whiskedaway Posted November 8, 2009 Author Share Posted November 8, 2009 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 https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/#findComment-953448 Share on other sites More sharing options...
MadTechie Posted November 8, 2009 Share Posted November 8, 2009 shouldn't <input type="submit" name="Search" value="Search"> be <input type="submit" name="do" value="Search"> OR switch (@$_POST['do']) { be switch (@$_POST['Search']) { As $_POST['do'] isn't in the form Link to comment https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/#findComment-953461 Share on other sites More sharing options...
whiskedaway Posted November 8, 2009 Author Share Posted November 8, 2009 Thank you! I added <input type="hidden" name="do" value="search"> and that fixed everything. I knew I'd done something really dumb! Link to comment https://forums.phpfreaks.com/topic/180636-solved-if-isset-not-working/#findComment-953472 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.