$_POST NOT WORKING

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

$_POST NOT WORKING

Post by fugix »

Hey guys.
For some reason I am not able to get $POST[] to work with this form I have. I get an error that it isnt recognizing the index: pus that i used for my submit button name...but im not sure as to why it isnt accepting it..heres a snippet of my code


$pui = $_POST['pui'];
$pci = $_POST['pci'];
$pus = $_POST['pus'];

if($pus)
{
$temp = $_FILES['pui']['tmp_name'];
$name = $_FILES['pui']['name'];
$photosize = $_FILES['pui']['size'];
$defaultcaption = "Add a Caption...";
if($pui&&$pci)
{


if($photosize > 1048576)
{
$errmsg = "Please choose a photo before posting!";
$errhdr = "Invalid Photo!";
echo "<div id='mwds' class='warningdivshadow'></div>
<div id='mwd' class='warningdiv'><div id='wds' width='500' class='warningdivspan'>
<span class='warningmessageheader'>".$errhdr."</span></div>
<span class='warningmessage'>".$errmsg."</span></div>
<meta http-equiv='refresh' content='3'>
";
}
else
{
$userid = $_SESSION['id'];
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$date = date("n/j/Y");
$time = date("g:i a");
$photopath = "members/".$_SESSION['id']."/".$name."";
$cquery = mysql_query("INSERT INTO updates VALUES ('', '$userid', '$firstname', '$lastname', '', '$date', '$time', '$photoname', '', '$photopath', '', '', '', '', '', '$pci')");
move_uploaded_file($temp, "members/".$_SESSION['id']."/".$name);

if($cquery)
echo "<meta http-equiv='refresh' content='1'>";
}
}
elseif($pui)
{

if($photosize > 1048576)
{
$errmsg = "Please choose a photo before posting!";
$errhdr = "Invalid Photo!";
echo "<div id='mwds' class='warningdivshadow'></div>
<div id='mwd' class='warningdiv'><div id='wds' width='500' class='warningdivspan'>
<span class='warningmessageheader'>".$errhdr."</span></div>
<span class='warningmessage'>".$errmsg."</span></div>
<meta http-equiv='refresh' content='3'>
";
}
else
{
$userid = $_SESSION['id'];
$firstname = $_SESSION['firstname'];
$lastname = $_SESSION['lastname'];
$date = date("n/j/Y");
$time = date("g:i a");
$photopath = "members/".$_SESSION['id']."/".$name."";
$cquery = mysql_query("INSERT INTO updates VALUES ('', '$userid', '$firstname', '$lastname', '', '$date', '$time', '$photoname', '', '$photopath', '', '', '', '', '', '')");
move_uploaded_file($temp, "members/".$_SESSION['id']."/".$name);

if($cquery)
echo "<meta http-equiv='refresh' content='1'>";
}
}
else
{
$errmsg = "Test!";
$errhdr = "Invalid Photo!";
echo "<div id='mwds' class='warningdivshadow'></div>
<div id='mwd' class='warningdiv'><div id='wds' width='500' class='warningdivspan'>
<span class='warningmessageheader'>".$errhdr."</span></div>
<span class='warningmessage'>".$errmsg."</span></div>
<meta http-equiv='refresh' content='3'>
";
}
}
$errhdr = "Upload a Photo";
echo "<div id='put'><div class='puds'></div>
<div id='pud' class='pud'><div id='wds' width='500' class='warningdivspan'>
<span class='warningmessageheader'>".$errhdr."</span></div>"; ?>
<form action='ownerphotos.php' method="POST" enctype="multipart/form-data">
<input class='pui' type='file' name="pui" /><br />
<input class='pci' type='text' name="pci" value='Add a Caption...' onfocus="if (this.value==defaultValue)value=''" onblur="if (this.value=='') this.value=defaultValue" />
<input type='submit' name="pus" class="pus" value='Post' />
</form>


Any thoughts as to what could be causing this?? Thank You
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: $_POST NOT WORKING

Post by social_experiment »

Try placing this around the code you want to execute when the submit button is clicked

Code: Select all

<?php
 if (isset($_POST['pus'])) {
 // your code
 }
I think it's not picking up the $_POST values because the form has not been submitted. Also, use the PHP Code button to encase your php code, it greatly improves your odds of getting helped.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_POST NOT WORKING

Post by fugix »

but how is it not submitted? when i'm pressing the submit button...?
jeyajeya
Forum Newbie
Posts: 2
Joined: Mon Mar 28, 2011 2:35 am

Re: $_POST NOT WORKING

Post by jeyajeya »

hi,
When i compile the simple client code, i got the bellow error...
"CGI Error
The specified CGI application misbehaved by not returning a complete set of HTTP headers. The headers it did return are:"

Kindly explain y htis is coming and hoe to fix this issue...

Jeyajeya
jeyajeya
Forum Newbie
Posts: 2
Joined: Mon Mar 28, 2011 2:35 am

Re: $_POST NOT WORKING

Post by jeyajeya »

Hi,
All , though this may be an unrelated error reporting in this page kindly send reply and help to fix this issue...

Jeya
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: $_POST NOT WORKING

Post by social_experiment »

fugix wrote:but how is it not submitted? when i'm pressing the submit button...?
The sample code i gave you was to check IF the button has been clicked, and only after that your code will be code executed.

Code: Select all

<form action='ownerphotos.php' method="POST" enctype="multipart/form-data">
<!-- change to this -->
<form action="ownerphotos.php" method="POST" enctype="multipart/form-data">
Try the above as well.
Hth
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
fugix
Forum Contributor
Posts: 207
Joined: Fri Mar 18, 2011 8:01 pm

Re: $_POST NOT WORKING

Post by fugix »

was a dumb mistake on my part. $_POST['pui'] needed to be $_FILES['pui']. sometimes when you stare at code for too long you overlook the simple things....thank you for helping me i appreciate it
Post Reply