Jump to content

[SOLVED] two POST forms in one doc


onthespot

Recommended Posts

hey, my code

 

<?php


$query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$acomment')";
if (!empty($_POST)) {
    // processing logic

if(!$acomment || strlen($acomment = trim($acomment)) == 0)
    echo "Comment not entered";
else if(!$acomment || strlen($acomment = trim($acomment)) < 10)
    echo "Comment too short, must be 10 characters at least";
else if (!$acomment || strlen($acomment = trim($acomment)) > 10){
    echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. ";
   mysql_query($query);}}

?>


<?php


$query2="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type2','$user2', now(), '$comment2')";
if (!empty($_POST)) {
    // processing logic

if(!$comment2 || strlen($comment2 = trim($comment2)) == 0)
    echo "Comment not entered";
else if(!$comment2 || strlen($comment2 = trim($comment2)) < 10)
    echo "Comment too short, must be 10 characters at least";
else if (!$comment2 || strlen($comment2 = trim($comment2)) > 10){
    echo "".$_SESSION['username'].", you have added recognition to ".$_POST['recuser']."'s Profile. ";
   mysql_query($query2);}}

?>

 

How can I seperate these so that they have a unique way of being different when i submit them?? At the moment when one is submitted, the other says no comment entered. Any way around this? Cheers

Link to comment
https://forums.phpfreaks.com/topic/170671-solved-two-post-forms-in-one-doc/
Share on other sites

I must be confused as to what the question is...because with 300+ posts I would hope this would be more obvious by now...If you have two POST forms submitting to the same PHP script then add a post variable to each form named "submissionForm" and have it be unique between each form:

 

Form 1 add:

<input type=hidden name=submissionForm value="form1">

 

Form 2 add:

<input type=hidden name=submissionForm value="form2">

 

Change code to:

 

<?php

if (!empty($_POST)) {

if($submissionFrom == "form1")
{
    $query="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type','$user', now(), '$acomment')";

    // processing logic

    if(!$acomment || strlen($acomment = trim($acomment)) == 0)
        echo "Comment not entered";
    else if(!$acomment || strlen($acomment = trim($acomment)) < 10)
        echo "Comment too short, must be 10 characters at least";
    else if (!$acomment || strlen($acomment = trim($acomment)) > 10){
        echo "".$_SESSION['username'].", you have added an award to ".$_POST['awarduser']."'s Profile. ";
       mysql_query($query);}
}
else if($submissionFrom == "form2")
{
    $query2="INSERT INTO ".TBL_AWARDS." VALUES (NULL, '$type2','$user2', now(), '$comment2')";

    // processing logic

    if(!$comment2 || strlen($comment2 = trim($comment2)) == 0)
        echo "Comment not entered";
    else if(!$comment2 || strlen($comment2 = trim($comment2)) < 10)
        echo "Comment too short, must be 10 characters at least";
    else if (!$comment2 || strlen($comment2 = trim($comment2)) > 10){
        echo "".$_SESSION['username'].", you have added recognition to ".$_POST['recuser']."'s Profile. ";
       mysql_query($query2);}
}
else
{
   echo "Where is this request coming from";
}

?>

 

Please note that there are ALOT of coding issues with your code. For one, you insert into the database before you do your error checking...

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.