Forum Moderators: coopster

Message Too Old, No Replies

Getting the Wrong data from $ POST

         

LividChihuahua

4:28 am on Sep 23, 2008 (gmt 0)

10+ Year Member



I can't figure out why this isn't working, so since I've googled this site and seen some helpful stuff I'm wondering if anybody here can help me with this.

I have 2 pages, one has a submission field with a bunch of variables in it and the other takes all this information and will make a few files and set things up for the script to easily read, the end result will kinda be a bulletin board using flat files, anyways this is the submission field:


echo "<div>";
echo "<form action='/submit.php' method='post' enctype='multipart/form-data'>";
// User Feilds
echo "<b>Game Name: </b> <input type='text' name='sub_name' size='50' /><br />";
echo "Game Image: <input name='sub_image' type='file' /> <br />";
echo "Number of Players: <select>";
echo "<option name='sub_players' value='unknown'>?</option>";
echo "<option name='sub_players' value='1'>1</option>";
echo "<option name='sub_players' value='2'>2</option>";
echo "<option name='sub_players' value='3'>3</option>";
echo "<option name='sub_players' value='4'>4</option>";
echo "<option name='sub_players' value='5'>5</option>";
echo "<option name='sub_players' value='6'>6</option>";
echo "<option name='sub_players' value='7'>7</option>";
echo "<option name='sub_players' value='8'>8</option>";
echo "</select> <br />";
echo "Release Date: <input type='text' name='sub_date' size='20' /><br />";
echo "Publisher: <input type='text' name='sub_publisher' size='30' /><br />";
echo "Genre: <select>";
echo "<option name='sub_genre' value='unknown'>?</option>";
echo "<option name='sub_genre' value='action'>Action</option>";
echo "<option name='sub_genre' value='casual'>Casual</option>";
echo "<option name='sub_genre' value='other'>Other</option>";
echo "<option name='sub_genre' value='poker'>Poker</option>";
echo "<option name='sub_genre' value='puzzle'>Puzzle</option>";
echo "<option name='sub_genre' value='racing'>Racing</option>";
echo "<option name='sub_genre' value='shooter'>Shooter</option>";
echo "<option name='sub_genre' value='sim'>Simulation</option>";
echo "</select> <br />";
echo "Online: <input type='checkbox' name='sub_online'/><br />";
echo "Mii Support: <input type='checkbox' name='sub_miisupport'/><br />";
echo "DLC: <input type='checkbox' name='sub_dlc'/><br />";
echo "Wii Points: <input type='text' name='sub_points' size='10' /><br />";
echo "ESRB Rating: <select>";
echo "<option name='sub_rating' value='unknown'>?</option>";
echo "<option name='sub_rating' value='ec'>Early Childhood</option>";
echo "<option name='sub_rating' value='e'>Everyone</option>";
echo "<option name='sub_rating' value='e10plus'>Everyone 10+</option>";
echo "<option name='sub_rating' value='t'>Teen</option>";
echo "<option name='sub_rating' value='m'>Mature</option>";
echo "<option name='sub_rating' value='ao'>Adults Only 18+</option>";
echo "</select> <br />";
echo "Description: <textarea rows='10' cols='45' name='sub_description'></textarea>";
// Hidden feilds
echo "<input type='hidden' name='sub_type' value='ware' /><br />";
// Submit Info
echo "<b>Bold</b> Feilds are required ";
echo " <input type='submit' value='Make Game' />";
echo "</form>";
echo "</div>";

And that works pretty good, the image upload seems to work (it dosen't give me an error at least) but the rest of my varibles seem messed up, like when I try and get $_POST['sub_name'] I actually get $_POST['sub_date'] and I can't figure out why. This is the code I'm using to get the information:

<?php
// Get information from previous page/
echo '<pre><b>Getting information...</b><br />';
// Getting Game Name
$name = $_POST["sub_name"];
echo $_POST['1'];
echo "the name is $name yes it is<br />";
// Getting File Upload
if ((($_FILES["sub_image"]["type"] == "image/gif")
¦¦ ($_FILES["sub_image"]["type"] == "image/jpeg")
¦¦ ($_FILES["sub_image"]["type"] == "image/pjpeg"))
¦¦ ($_FILES["sub_image"]["type"] == "image/png")) {
if ($_FILES["sub_image"]["error"] > 0) {
echo "Error: " . $_FILES["sub_image"]["error"] . "<br />";
} else {
echo "Game Image Name: " . $_FILES["sub_image"]["name"] . "<br />";
echo "Game Image Type: " . $_FILES["sub_image"]["type"] . "<br />";
echo "Game Image Size: " . ($_FILES["sub_image"]["size"] / 1024) . " Kb<br />";
}
} else {
echo "Game Image File Type Invalid.<br />";
}

?>


A copy is running running here: <snip> whatever you put in the release date field will come up as the name, it's reliable about it now. Anybody know what I'm doing wrong or have any advice to figure out whats wrong?

[edited by: eelixduppy at 4:52 am (utc) on Sep. 23, 2008]
[edit reason] no URLs, please [/edit]

Anyango

6:34 am on Sep 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi LividChihuahua

I tried your code and it appears to work fine even without any modification, $_POST['sub_name'] shows correctly for me, also $_POST['sub_date'].

try this to get a list of all $_POST values to see if you are getting correct values on submit.php, if yes then it could be a duplicate variable name somewhere in your code, overwriting existing value.

this goes on top of your submit.php just to check,

echo "<pre>";
print_r($_POST);
echo "</pre>";

LividChihuahua

7:08 am on Sep 23, 2008 (gmt 0)

10+ Year Member



I did that after testing (read is somwhre on this site) and I get this
Array
(
[sub_name] => date
[sub_publisher] =>
[sub_online] => on
[sub_miisupport] => on
[sub_dlc] => on
[sub_points] => Wii Points
[sub_description] => Description

description
[sub_type] => ware
)
I don't even have a sub_date? and none of my drop down menus are working either, but that may be another problem I just noticed it and havent check into it yet

Anyango

7:31 am on Sep 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This is what i get when i view $_POST, with your exact code.

Array
(
[sub_name] => Test NAME
[sub_date] => Test Date
[sub_publisher] => edsdsdsdsd
[sub_online] => on
[sub_miisupport] => on
[sub_dlc] => on
[sub_points] => 23232
[sub_description] => asdasdasdas
[sub_type] => ware
)

LividChihuahua

8:43 am on Sep 23, 2008 (gmt 0)

10+ Year Member



I made a test page and it seems to work fine, if I load the file directly insted of through the index (it's set to require it) then I get them all, even get the number of players from the drop down menu (but only that one drop down menu) just fine. Have any ideal on how to figure out why it won't work when it's included?

LividChihuahua

8:46 am on Sep 23, 2008 (gmt 0)

10+ Year Member



Okay last littel bit of test, my test page with the same code I posted here pasted in works fine, and if I pull that single file I get my first drop down menu's result too, but only then. I could put all the files here, but thats seems like a waste, besides it's my site, no need for you to do all the work :P

LividChihuahua

10:21 pm on Sep 23, 2008 (gmt 0)

10+ Year Member



Well a poked around and it's working now, I diden't change anything so i don't have a clue how it got fixed but it seems to be working great, even getting all the information from the drop down menu's. Thanks for the help

Anyango

5:59 am on Sep 24, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yep the code appeared ok already. Glad it works now