Jump to content

$_POST is empty


linkcool

Recommended Posts

Hi everybody, im linkcool, im new here and i have a little problem.

I've been making some php for about 2 weeks now and i got a problem with a form and a $_POST.

 

here is the upload.php file, it gets redirected into uploadverify.php

 

<?php
session_start();
if(!session_is_registered(username))
{
	session_register("wrongpage");
	$_SESSION['wrongpage'] = "Sorry you are not logged in so you can't visit this page: Upload.php <br/>";
header("location:login.php");
}
else{}
echo '<table border="0"><tr><td width="500"> </td><td><a href="logout.php">Logout!</a></td></t></table><br/	>';
echo "All kind of files are supported <br/><br/>";
?>
<table>
<form action="UploadVerify.php" method="post" enctype="multipart/form-data">
<tr>
<label for="file"><td width="200">Filename:</td></label>
<td><input type="file" name="file" id="file" /></td>
</tr>
<tr>
<td>Description: (optionnal)</td><td><input type="text" name="description" /></td>
</tr>
<tr>
<td>
Album: </td>
<td>
<input type="text" name="something1" />
</td>
</tr>
<tr>
<td></td><td><input type="submit" name="submit" value="Upload!" /></td>
</tr>
</form>
</table>
<?php
echo 'New feature!:<br/>';
echo '<a href="view.php">View all YOUR uploaded images</a>'
?>

 

It is a form where the user uploads a file and write something in the description textbox and something in the "something1" textbox(it was "album" before).

So when the user click: upload!, it makes the uploadverify.php action. In there, the user can see the description as he writen it in the textbox, but the album dont show up. And they are both same input.

I tryed the var_dump($_POST['something1']) and it does not return it as NULL, it returns as:

string(0) ""

.

 

So does anyone know how to make the $_POST['something1'] have it's value? because it returns empty...

And why the $_POST['description'] does not return empty?

 

thank you,

linkcool

Link to comment
Share on other sites

Your code in UploadVerify.php must be overwriting the value (we would need to see the code to be able to tell) or register_globals are on and you have a same name session or cookie variable that is overwriting the value.

 

Your code is also using session_is_registered/session_register and session_start/$_SESSION variables at the same time. You should only be using session_start/$_SESSION variables both because you should not mix the two methods and because session_is_registered/session_register was depreciated nearly 8 years ago and will be completely removed in php6.

 

You also need an exit; statement after your header redirect to prevent the remainder of the code on the page from executing. Your existing code does not protect anything.

Link to comment
Share on other sites

Your code in UploadVerify.php must be overwriting the value (we would need to see the code to be able to tell) or register_globals are on and you have a same name session or cookie variable that is overwriting the value.

 

Your code is also using session_is_registered/session_register and session_start/$_SESSION variables at the same time. You should only be using session_start/$_SESSION variables both because you should not mix the two methods and because session_is_registered/session_register was depreciated nearly 8 years ago and will be completely removed in php6.

 

You also need an exit; statement after your header redirect to prevent the remainder of the code on the page from executing. Your existing code does not protect anything.

 

 

Woaw, i never tought about that but your first paragraph sayd it all, I accidently overwited the value, i writed:

if($_POST['something1'] = "" ){

instead of

if($_POST['something1'] == ""){

 

But what should i use instead of all that session stuff?

 

and, are you sure the exit; statement will "play" if i redirect, and what it does??

 

Anyway, thank you very much.

 

linkcool

Link to comment
Share on other sites

But what should i use instead of all that session stuff?

 

isset($_SESSION['some_name']) would generally be used instead of session_is_registered() and setting a $_SESSION variable is the same as using session_register() and a regular variable name (since you are not referencing $wrongpage, your use of session_register() has no affect any way.)

 

The specific code you have at that start of your file should be -

 

<?php
session_start();
if(!isset($_SESSION['username']))
{
$_SESSION['wrongpage'] = "Sorry you are not logged in so you can't visit this page: Upload.php <br/>";
header("location:login.php");
exit;
}
echo .....

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.