1

I submit the data to post[submit] and post[request] from two different buttons.

I submitted user_id to post[submit] but i am unable to echo the user_id in request portion (post[request])

/* passing the data from two different form*/

if(isset($_POST['submit']) || isset($_POST['request']) ){            
    if(isset($_POST['submit'])){
        echo "submit working ";
        $user_id= $_POST['user_id'];
        echo $user_id; /* this id passed from submit form*/
    }
    else{
        echo "Request Portion Working";
        echo $user_id;  /*this line gives the error*/
    }            
}

I submit the data to post[submit] and post[request] from two different buttons.
I submitted user_id to post[submit] but i am unable to echo the user_id in request portion (post[request]) 
Karl Gjertsen
  • 4,690
  • 8
  • 41
  • 64
Super
  • 19
  • 1

3 Answers3

1

Try this,

if(isset($_POST['submit']) || isset($_POST['request']) ){
    $user_id= $_POST['user_id'];

    if(isset($_POST['submit'])){
       echo "submit working ";
       echo $user_id; /* this id passed from submit form*/
    }else{
       echo "Request Portion Working";
       echo $user_id;  /*this line gives the error*/
    }

}
K.B
  • 885
  • 5
  • 10
0

While calling a variable in a function you need to make sure that it is in scope. Else it would not be recognized.

if(isset($_POST['submit']) || isset($_POST['request']) ){
    if(isset($_POST['user_id']) {
      $user_id = $_POST['user_id'];
      if(isset($_POST['submit'])){
         echo "submit working ";
         echo $user_id; /* this id passed from submit form*/
      } else {
         echo "Request Portion Working";
         echo $user_id;  /*this line gives the error*/
      }  
    } else {
        echo 'User_Id not set';
}
Trishant Pahwa
  • 2,559
  • 2
  • 14
  • 31
0

in your code when $_POST['request'] send then you do not $_POST['user_id'] so get your user_id for any condition so you use this all condition, you can use also trim to remove space

<?php
$user_id = ''; // assign variable 
if(isset($_POST['submit']) || isset($_POST['request']) ){
     $user_id= trim($_POST['user_id']); // get your user_id for any condition so you use this all condition, you can use also trim to remove space
    if(isset($_POST['submit'])){
        echo "submit working ";
        echo $user_id; /* this id passed from submit form*/
    }
    else{
        echo "Request Portion Working";
        echo $user_id;  /*this line gives the error*/
    }            
} else {
     echo "No Post request";
}
Shafiqul Islam
  • 5,570
  • 2
  • 34
  • 43