Jump to content

[SOLVED] PHP extract not working


gnawz

Recommended Posts

I have used this before and it worked...


<?php
if (!defined('WEB_ROOT')) 
{
exit;
}

if (isset($_GET['ProjectID']) && (int)$_GET['ProjectID'] > 0) 
{
$ProjectID = (int)$_GET['ProjectID'];
} 

$sql = "SELECT * FROM prismprojects WHERE ProjectID = '$ProjectID'";
$result = dbQuery($sql);		
extract(dbFetchAssoc($result));
?>

<table width="100%" border="0" cellpadding="5">
  <tr> 
    <td colspan="3" class="title_text">Details</td>
  </tr>
  <tr> 
    <td width="143" valign="top">Overall Project Title</td>
    <td width="791" colspan="2" bgcolor="#FFFFFF"> 
      <?php	echo $OverallProjectTitle; ?>
    </td>
  </tr>
  <tr> 
    <td valign="top" class="style3 tdcontent">Specific Project</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $SpecificProject; ?></td>
  </tr>
  <tr> 
    <td valign="top" class="style3 tdcontent">Partner Organisation</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $PartnerOrganisation; ?></td>
  </tr>
  <tr> 
    <td valign="top" class="style3 tdcontent">Country</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $Country; ?></td>
  </tr>
  <tr>
    <td valign="top" class="style3 tdcontent">Sector</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $Sector; ?></td>
  </tr>
  <tr> 
    <td valign="top" class="style3 tdcontent">Value</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $Value; ?></td>
  </tr>
  <tr> 
    <td valign="top" class="style3 tdcontent">Date created</td>
    <td colspan="2" bgcolor="#FFFFFF"><?php echo $DateAdded; ?></td>
  </tr>
  <tr> 
    <td colspan="3" class="tdcontent"> <div align="center">   
        <input name="btnBack" type="button" id="btnBack" value=" Back " onClick="window.history.back();" class="button_image">
      </div></td>
  </tr>
</table>
<?

?>


 

I get these errors.....

 

 

Notice: Undefined variable: ProjectID in C:\xampp\htdocs\prism\admin\portfolio\detail.php on line 12

 

Warning: extract() [function.extract]: First argument should be an array in C:\xampp\htdocs\prism\admin\portfolio\detail.php on line 14

 

 

What could be the problem??

Link to comment
https://forums.phpfreaks.com/topic/124446-solved-php-extract-not-working/
Share on other sites

What if $ProjectID is not set? You should add an else and set a default or tell the user they have selected an invalid project id.

 

The second error is a result of the first notice because its saying that the variable is not defined which means that $result does not contain a MySQL Resource ID which means extract will fail. You need more error checking, to ensure these errors don't occur.

 

(Yeah what Scott said. :P)

Thanks guys,

 

I have seen the error. I had to remove a space in my list.php file where a user clicks before going to detail.php

 

<?php echo $_SERVER['PHP_SELF']; ?>?view=detail&ProjectID=<?php echo $ProjectID; ?>

 

There was a space between ProjectID  AND  = which means ProjectID had not been set

 

Thanks alot.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.