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

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.