dongzong8110 2015-07-15 09:55
浏览 57

php未定义索引变量跟随程序[重复]

Hi trying to following program

<?php

//define class database connectivity
class dbconnect
{
    var $conn;

  function dbcon()
    {

    if(!isset($conn))           //database connectivity
        {
        $conn = mysqli_connect('localhost','root','username','password');
        }
        if($conn==false)
        {
        return mysqli_connect_error();   // return error message if connection fails
        }
        return $conn;           // return connectivity 
    }
    }

//define class sql injection
class injection extends dbconnect
{
    function inject($char)
    {
        $data=new dbconnect;
        $dataobj=$data->dbcon();                // create object database connection

        $char=trim($char);                      //inject whitespace
        $char = stripcslashes($char);               // inject slashes 
        $char = htmlspecialchars($char);                // inject special characters
        $char = mysqli_real_escape_string($dataobj,$char);  // mysql injection variable,databaseobject variable
        return $char;                           // return safe data
    }
}
$injobj=new injection;
$injobj->inject("name");                        //create object sql injection class

//define the class staff
class staff
{

function stafffun()
        {
        $dbconnection = new dbconnect;              //create database object
        $dbobj= $dbconnection->dbcon(); 
        $sql = "SELECT username from team_management where status='1'" ;

             // select data from table

        $rs = mysqli_query($dbobj,$sql);


            $select = "<select name='username'>"; 

            // output data of each row
            while($row = mysqli_fetch_array($rs)) 
        {
        $select.="
        <option value='".$row["username"]."'>"."</option>";

        }  
        $select.="</select>"; 

        return $select;
    }
}
$staffobj1=new staff;
$staffobj2 = $staffobj1->stafffun();

class state
{

function statefun()
        {
        $dbconnection = new dbconnect;              //create database object
        $dbobj= $dbconnection->dbcon(); 
        $sql = "select name from newstates where ccode=122" ;

// select data from table
        $rs = mysqli_query($dbobj,$sql);

            $select = "<select name='name'>"; 
            // output data of each row
            while($row = mysqli_fetch_array($rs)) 
        {
        $select.="
        <option value='".$row["name"]."'>"."</option>";
        }  
        $select.="</select>"; 
        return $select;
    }
}
$stateobj1=new state;
$stateobj2 = $stateobj1->statefun();

//define class allocate 
class allocate 
{
function allocatefun($state,$staff)
        {
        $dbconnection = new dbconnect;              //create database object
        $dbobj= $dbconnection->dbcon(); 
        for($i=0;$i<7;$i++)
        {

        $rs="insert into v2_followup_history1(profileid) select pro_profileid from profile 
            where pro_state='$state' and pro_adminappstatus='1'and pro_profileid not in(select profileid from               v2_followup_histroy1) ORDER BY RAND() LIMIT 120)";

        }

        //update the datafollowup_history1 table
        $upda="update v2_followup_history1 set flw_staff='$staff',date=curdate(),status='1'";
        $result=mysqli_query($dbobj,$upda);
        if($result)
        echo "success";
        else
        echo "fail";
    }
}
if(isset($_POST['submit']))
{
$state=$_POST['pro_state'];


$staff=$_POST['flw_staff'];
$allobj1=new allocate ;
$allobj2 = $allobj1->allocatefun($state,$staff);

}
?>
<!DOCTYPE HTML>
<html>
<head>



 </head>

 <body oncontextmenu="return false">  <!--- Right click enable to the website --->
<form name="frm" method="post">
  Staff Name: 
 <?php echo $staffobj2;?>


State 
    <?php echo $stateobj2;?><br><br>



<input type="submit" name="submit"  value="submit" > 
</form>
</body>
</html>

It display the error page

Notice: Undefined index: pro_state in /var/www/vhosts/alpha.nikah.com/httpdocs/testcode/demo/profile.php on line 125

Notice: Undefined index: flw_staff in /var/www/vhosts/alpha.nikah.com/httpdocs/testcode/demo/profile.php on line 128

success 

Please help me how can i retrieve

</div>
  • 写回答

1条回答 默认 最新

  • dtpn60029 2015-07-15 10:08
    关注

    First your state field is called 'name' but you are looking for a 'pro_state' POST value. So change:

     $select = "<select name='name'>";
    

    ...to...

     $select = "<select name='pro_state'>"; 
    

    Also you are trying to access the POST value 'flw_staff' but don't have any fields in your form with that name.

    评论

报告相同问题?

悬赏问题

  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂
  • ¥15 wordpress 产品图片 GIF 没法显示
  • ¥15 求三国群英传pl国战时间的修改方法
  • ¥15 matlab代码代写,需写出详细代码,代价私
  • ¥15 ROS系统搭建请教(跨境电商用途)