php&&关于Post方法的mysql

时间:2017-07-25 09:23:07

标签: javascript php html mysql css3

我提交数据以发布[提交]并从两个不同的按钮发布[请求]。

我提交了user_id以发布[提交],但我无法回应请求部分中的user_id(发布[请求])

/ *从两种不同的形式传递数据* /

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]) 

3 个答案:

答案 0 :(得分:1)

试试这个,

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*/
    }

}

答案 1 :(得分:0)

在函数中调用变量时,需要确保它在范围内。否则就不会被承认。

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';
}

答案 2 :(得分:0)

$_POST['request']发送时你的代码中的

然后你没有$_POST['user_id']所以为任何条件获取你的user_id所以你使用这个条件,你也可以使用trim来删除空间

<?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";
}