Undefined Index when using post

前端 未结 1 734
礼貌的吻别
礼貌的吻别 2021-01-17 01:38

I\'m getting undefined index errors on the $_POST variables. I.E. $_POST[\'hostname\']. I know kinda why I\'m getting them, but is there a way to keep the php and form in th

相关标签:
1条回答
  • 2021-01-17 02:18

    Wrap your PHP code in an if with an isset condition. This way, the code will only be run if the form has been submitted:

    if(isset($_POST['submit']))
    {
        include_once("config.php");
        $date = date('Y-m-d');
    
        //Database Variables
        $dbhost = strip_tags($_POST['hostname']);
        $dbuser = strip_tags($_POST['dbuser']);
        $dbpass = strip_tags($_POST['dbpassword']);
        $submit = isset($_POST['submit']);
    }
    
    0 讨论(0)
提交回复
热议问题