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
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)

Link to comment
Share on other sites

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.

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.