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
$_POST NOT WORKING
Moderator: General Moderators
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: $_POST NOT WORKING
Try placing this around the code you want to execute when the submit button is clicked
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.
Code: Select all
<?php
if (isset($_POST['pus'])) {
// your code
}
“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
Re: $_POST NOT WORKING
but how is it not submitted? when i'm pressing the submit button...?
Re: $_POST NOT WORKING
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
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
Re: $_POST NOT WORKING
Hi,
All , though this may be an unrelated error reporting in this page kindly send reply and help to fix this issue...
Jeya
All , though this may be an unrelated error reporting in this page kindly send reply and help to fix this issue...
Jeya
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: $_POST NOT WORKING
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.fugix wrote:but how is it not submitted? when i'm pressing the submit button...?
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">
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
Re: $_POST NOT WORKING
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