Page 1 of 1

Variable $file not passing with a form... help!

Posted: Wed May 24, 2006 10:50 am
by Citizen
For some reason, the variable $file isn't passing with the rest of the variables. All of the other variables worked fine, just not this one.

Here's my code:

Code: Select all

<?php

include("../../inc/config/connect.inc");

include("header.php");

protect();

if (member_types2($VAR[4]) != '0') {
	echo "<p>Sorry, but you must be logged in as an administrator to view this area.";
}
else
{
include("menu.php");

if ($submit) {
$shortname = strip_tags($shortname);
$shortname = trim($shortname);
$title = strip_tags($title);
$title = trim($title);
$width = strip_tags($width);
$width = trim($width);
$file = strip_tags($file);
$file = trim($file);
$height = strip_tags($height);
$height = trim($height);
$miniimage = strip_tags($miniimage);
$miniimage = trim($miniimage);
$stdimage = strip_tags($stdimage);
$stdimage = trim($stdimage);
$isreverse = strip_tags($isreverse);
$isreverse = trim($isreverse);
	if ($shortname == "") {
echo "<p>Please enter a category name.";
	}
	else if ($title == "") {
echo "<p>Please enter a valid title.";
	}
	else if ($description == "") {
echo "<p>Please enter a valid description.";
	}
	else if ($file == "") {
echo "<p>Please enter a valid .swf file name.";
	}
	else if ($miniimage == "") {
echo "<p>Please enter a valid mini image name.";
	}
	else if ($stdimage == "") {
echo "<p>Please enter a valid standard image name.";
	}
	else if ($isreverse == "") {
echo "<p>Please enter a valid reverse score setting.";
	}
	else {
$sql = "INSERT INTO `arcade_games` (shortname, title, description, file, width, height, miniimage, stdimage, isreverse) VALUES ('$shortname', '$title', '$description', '$file', '$width', '$height',  '$miniimage', '$stdimage', '$isreverse')";
$result=mysql_query($sql) or die(mysql_error());
echo "Congratulations, your arcade category has been entered!";
	}
}
echo"
<h2>Add a new game:</h2>
<p>In most cases, you will need to look at the <br />default install file (usually install.php or name.game.php) that <br />came with the game you are trying to install.
<p>
<form method='post' action='$PHP_SELF'>
<p><b>Shortname:</b></p>
The shortname sets what the game will be listed as inside the database. <br />This must correspond with the shortname specified in the game itself.<br /> It is usually the same as the filename.<br />
<input type='Text' name='shortname' value='$shortname' maxlength='25' size='25'>
<p><b>Title:</b></p>
<input type='Text' name='title' maxlength='25' value='$title'size='25'>
<p><b>Description:</b></p>
<input type='Text' name='description' maxlength='250' value='$description' size='100'>
<p><b>Width:</b></p>
<input type='Text' name='width' maxlength='4' value='$width' size='4'>
<p><b>Height:</b></p>
<input type='Text' name='height' maxlength='4' value='$height' size='4'>
<p><b>Miniature Image Name:</b></p>
<input type='Text' name='miniimage' maxlength='50' value='$miniimage' size='50'>
<p><b>Standard Image:</b></p>
<input type='Text' name='stdimage' maxlength='50' value='$stdimage' size='50'>
<p><b>File name</b></p>
<input type='Text' name='file' maxlength='50' value='$file' size='50'>
<p><b>Reverse Scoring:</b></p>
<br />Must be either 1 or 0. 1 for reverse scoring, 0 for normal scoring.<br /> If you dont know, it should probably be 0.<br />
<input type='Text' name='isreverse' maxlength='1' value='$isreverse' size='1'>
<p><b>Game Category:</b></p>
  <select name='categoryid'>
";
$sql="SELECT * FROM `arcade_categories` ORDER BY `displayorder`";
$result=mysql_query($sql);
$catnum = mysql_num_rows($result);
for($i = 0; $i < $catnum; $i++) { 
	$row = mysql_fetch_array($result);
	$catid = $row["catid"];
	$catname = $row["catname"];
	echo "
    <option value='$catid'>$catname</option>
	";
}
echo "
	</select>
<p>
<input type='Submit' name='submit' value='Submit'></p>
</form>
";
include("footer.php");
}
?>

Posted: Wed May 24, 2006 10:54 am
by JayBird
what do you see when you run this after submitting the form

Code: Select all

echo '<pre>';
print_r($_POST);
echo '</pre>';
Post the results here

Posted: Wed May 24, 2006 10:55 am
by neophyte
register_globals is not on would be my first guess. Try accessing it with $_POST['file'];

Posted: Wed May 24, 2006 10:58 am
by feyd
Run the following in a new file and tell us the results please.

Code: Select all

<?php

$neg = array(0, false, '', null, 'off');
$ve = phpversion();
$os = PHP_OS;
$er = intval(error_reporting());
$rg = (in_array(strtolower(ini_get('register_globals')), $neg) ? 'Off' : 'On');
$de = (in_array(strtolower(ini_get('display_errors')), $neg) ? 'Off' : 'On');
$so = (in_array(strtolower(ini_get('short_open_tag')), $neg) ? 'Off' : 'On');
$le = '';
$cli = (php_sapi_name() == 'cli');
$eol = ($cli ? "\n" : "<br />\n");

$gle = get_loaded_extensions();
$rows = array();
$wide = 4;
$j = count($gle);
$pad = $wide - $j % $wide;
$len = max(array_map('strlen', $gle));
$func = create_function('$a', 'return str_pad($a, ' . intval($len) . ');');
$gle = array_map($func, $gle);
for($i = 0; $i < $j; $i += $wide)
{
    $le .= '   ' . implode('   ', array_slice($gle, $i, $wide)) . "\n";
}
if ($cli)
{
     $le = $eol . $le;
}
else
{
 $le = '<pre>' . $le . '</pre>';
}

$ec = array(
   'E_STRICT' => 2048, 'E_ALL' => 2047, 'E_USER_NOTICE' => 1024,
   'E_USER_WARNING' => 512, 'E_USER_ERROR' => 256, 'E_COMPILE_WARNING' => 128,
   'E_COMPILE_ERROR' => 64, 'E_CORE_WARNING' => 32, 'E_CORE_ERROR' => 16,
   'E_NOTICE' => 8, 'E_PARSE' => 4, 'E_WARNING' => 2, 'E_ERROR' => 1,
);

$e = array();
$t = $er;
foreach ($ec as $n => $v)
{
   if (($t & $v) == $v)
   {
      $e[] = $n;
      $t ^= $v;
   }
}
$er = $er . ' (' . implode(' | ', $e) . ')';

if (!$cli)
{
  echo '<html><head><title>quick info</title></head><body>' . "\n";
}

echo 'PHP Version: ' . $ve . $eol;
echo 'PHP OS: ' . $os . $eol;
echo 'Error Reporting: ' . $er . $eol;
echo 'Register Globals: ' . $rg . $eol;
echo 'Short Tags: ' . $so . $eol;
echo 'Display Errors: ' . $de . $eol;
echo 'Loaded Extensions:' . $le . $eol;

if (!$cli)
{
  echo '</body></html>' . "\n";
}

?>

Posted: Wed May 24, 2006 11:55 am
by neophyte
Great idea Feyd.

Posted: Wed May 24, 2006 12:13 pm
by Citizen
I got it to work by using $file = $_POST['file'];

Im not sure why the variables were directly available without extracting them from $_POST while $file had to....


Anywho, here's the results from that script you posted:
PHP Version: 4.3.11
PHP OS: Linux
Error Reporting: 2039 (E_USER_NOTICE | E_USER_WARNING | E_USER_ERROR | E_COMPILE_WARNING | E_COMPILE_ERROR | E_CORE_WARNING | E_CORE_ERROR | E_PARSE | E_WARNING | E_ERROR)
Register Globals: On
Short Tags: On
Display Errors: On
Loaded Extensions:

xml tokenizer swf standard
sockets session posix pcre
overload mysql mcrypt mbstring
gd ftp curl ctype
calendar bcmath zlib apache
Zend Optimizer