简体   繁体   English

我在PHP上运行时遇到错误

[英]i am getting errors im running on PHP

$submit = $_POST['submit'];

$fullname = strip_tags($_POST['fullname']);

$username = strip_tags($_POST['username']);

$password = strip_tags($_POST['password']);

$repeatpassword = strip_tags($_POST['confirmpassword']);

$date = date ("Y-m-d");

i get **"Notice: Undefined index"**
but when i do this

if(isset($_POST['submit']))
{

$submit = $_POST['submit'];

$fullname = strip_tags($_POST['fullname']);

$username = strip_tags($_POST['username']);

$password = strip_tags($_POST['password']);

$repeatpassword = strip_tags($_POST['confirmpassword']);

$date = date ("Y-m-d");
}

the undefined index gets fixed but Notice: Undefined variable: submit is my new error why is that??? 未定义的索引得到修复,但注意:未定义的变量:Submit是我的新错误,为什么????

It's notice because you want to use variable which is not set you can fix it by checking it with isset() function 注意,因为您要使用未设置的变量,可以通过使用isset()函数检查它来修复它

$submit = null;

if(isset($_POST['submit'])
   $submit = $_POST['submit'];

or with short syntax 或语法简短

$submit = isset($_POST['submit']) ? $_POST['submit'] : null;

same applies to other variables passed via $_POST 同样适用于通过$ _POST传递的其他变量

试试看

$submit = isset ( $_POST ['submit'] ) ? $_POST ['submit'] : null ;

Change: 更改:

if(isset($_POST['submit']))

In: 在:

if(isset($_POST) && isset($_POST['submit']))

This is due to no value for 'submit' being passed by POST. 这是因为POST没有传递“ submit”的值。 Check if $_POST['submit'] is empty prior to assigning its value to a variable. 在将$ _POST ['submit']的值分配给变量之前,先检查其是否为空。

Do You have in your form 你有你的形式吗

<input type = 'submit' name = 'submit' />

if you have placed only 如果您只放置

  <input type = 'submit' /> 

It will not work 不起作用

Changed it to start with this 从此开始更改

<?php

 if(isset($_POST['submit']) != "")
 {

   $submit = $_POST['submit'];
   ......

 }

 ?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM