Jump to content

Simple Form Post Not working.


AbydosGater

Recommended Posts

Hi, i am going to copy a large section of the code for one of my message board systems here.
The problem lies in not errors, but when a user submits the form.. Its just displaying the form again, Not running the mysql query...

The code is as follows..
Ive even printed it off and read through it, i can see where im going wrong.

[code] <?php
if(!$_GET['action']){
//do while for messages
} else if ($_GET['action'] == "post"){
if (!$_POST['post']){
echo "
<p><font color='#FFFFFF'> To
        Post A Message Simpily Fill In The Box Below And Click Post.</font></p>
      <form action='?action=post' method='post' name='postmessage' id='postmessage'>
        <div align='center'><font color='#FFFFFF'>Title:
  <input name='title' type='text' id='title' value='RE: last message' class='field1'><br>
Your Message:<br>
          <textarea name='message' cols='70' rows='5' class='field1'></textarea>
          <br> ";
  if ($_SESSION['user']['CL'] == 10){
  echo "
  <select name='color' id='color' class='field1'>
    <option value='Green' selected>Green</option>
    <option value='Red'>Red</option>
    <option value='Yellow'>Yellow</option>
    <option value='Blue'>Blue</option>
    <option value='Pink'>Pink</option>
  </select>
  <br>
          <input type='submit' name='Post' value='Post' class='button1'>
          </font></div>
      </form>
  ";
  } else {
  echo "
<input name='color' type='hidden' id='color' value='Post'>
  <br>
          <input type='submit' name='Post' value='Post' class='button1'>
          </font></div>
      </form> ";
  }
} elseif ($_POST['Post'] && $_POST['message'] && $_POST['color']) {
$message = $_POST['message'];
$message = modifyPost($message);
$color = $_POST['color'];
$title = $_POST['title'];
$timestamp = DATESTAMP;
$member_id = $_SESSION['user']['member_id'];
mysql_query("INSERT INTO sf_tenforward (id, member_id, title, content, color, timestamp) VALUES (NULL, $member_id, $title, $message, $color, $timestamp)");
echo "<br><font color=white>Thank you for posting your message, Please click the link above to read your message and any replys.</font>";
} else {
echo "<br><font color=white>Sorry, Your message could not be posted, Please go back and make sure you filled in the form.</font>";
}
} else {
echo "<br><br><font color=white>Incorrect Action Presented.</font>";
}
?>[/code]
Sorry, its a big section of code.. Ehh but i cant see why the form is being displayed again..

Oh and PS. It will only display if the GET['action'] is set to post..

Otherwise it WILL run the //while for messages bit.
Its all in the form somewhere!
Can anyone see where ive gone wrong, i cant
Link to comment
https://forums.phpfreaks.com/topic/29333-simple-form-post-not-working/
Share on other sites

I don't understand your logic here, remove your GET action from the form action and simply sniff for the submit button instead. Either it is submitted or its not ( too many mix won't do the trics  ??? ):
[code]
<?php

if(isset($_POST['Post'])) // the name of your submit button
{
// form is submitted
}
else
{
// form is not submitted
}

?>
[/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.