Jump to content
MakeWebGames

Extract() Error


Aqua

Recommended Posts

Well i am making a VERY different, unique, game. But i am having some troubles with the following, the error message is;

 

Warning: extract(): First argument should be an array in /home/Hitman_Legacy/public_html/showmissions.php on line 16

 

Some of my code;

 

<?php
session_start();
require "global_func.php";
if($_SESSION['loggedin']==0) { header("Location: login.php");exit; }
$userid=$_SESSION['userid'];
require "header.php";
$h = new headers;
$h->startheaders();
include "mysql.php";
$sql = "SELECT username,title,Mission1,Mission2,Mission3,Mission4,Mission5,Mission6,Mission7,Mission8,Mission9,Mission10,Mission11,Mission12,Mission13,Mission14,Mission15,Mission16,Mission17,Mission18,Mission19,Mission20,Mission21,Mission22,Mission23,Mission24,Mission25,Mission26,Mission27,Mission28,Mission29,Mission30,submitedby,dateadded,membersnon,difficulty,reward,itemsneeded,startlocation,description,requirements FROM questguides WHERE title='$_POST[ftitle]'";
$result = mysql_query($sql)
or die(mysql_error());
$row = mysql_fetch_array($result);
[b]extract($row);[/b]
if ($title == "")
{
  include("viewmissions.php");
}
else
{
include("http://www.*****");
echo"This mission was submited by [b]$submitedby[/b]. It was added to the database by [b]$username[/b] on $dateadded


<font size='+1'>[b]$title[/b]</font>";
include("http://www.*****");
}
?>

 

Can someone please explain the actual function of extract, i know it sort of, but need a specific explanation. And give some examples if possible :p

PS: The code was done in a few minutes, it is not yet functional.

¬LK

Link to comment
Share on other sites

Re: Extract() Error

Turning array keys into variables, and asigning the array values of them to the variables.

 

int extract ( array $var_array [, int $extract_type [, string $prefix ]] )

 

This function is used to import variables from an array into the current symbol table. It takes an associative array var_array and treats keys as variable names and values as variable values. For each key/value pair it will create a variable in the current symbol table, subject to extract_type and prefix parameters.

 

Note: Beginning with version 4.0.5, this function returns the number of variables extracted. 

 

Note: EXTR_IF_EXISTS and EXTR_PREFIX_IF_EXISTS were introduced in version 4.2.0. 

 

Note: EXTR_REFS was introduced in version 4.3.0. 

 

extract() checks each key to see whether it has a valid variable name. It also checks for collisions with existing variables in the symbol table. The way invalid/numeric keys and collisions are treated is determined by the extract_type .

It is making variables out of the array key, and values.

A script to duplicate that would be;

<?php
$array = array('hello' => 'hi', 'world' => 'earth');
foreach($array as $key => $value) $$key = $value;

echo $hello;
?>

A coding error by some, a great wayto dynamically create variables for others.

Link to comment
Share on other sites

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.   Paste as plain text instead

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