Php 注意:未定义索引:(isset not work)
我试图注册一个创建自动密码并通过电子邮件发送,但每当执行代码时,我在所有字段中都会出现此错误(注意:未定义索引:)。请帮忙 issetPhp 注意:未定义索引:(isset not work),php,mysqli,isset,Php,Mysqli,Isset,我试图注册一个创建自动密码并通过电子邮件发送,但每当执行代码时,我在所有字段中都会出现此错误(注意:未定义索引:)。请帮忙 isset //whether the name is blank if (isset($_POST['name']) and $_POST['name'] == '') { $_SESSION['error']['name'] = "First Name is required."; } 配置 <?php session_start();
//whether the name is blank
if (isset($_POST['name']) and $_POST['name'] == '')
{
$_SESSION['error']['name'] = "First Name is required.";
}
配置
<?php
session_start();
include('/includes/db2.inc.php');
if(isset($_POST['submit']))
{
//whether the name is blank
if($_POST['name'] == '')
{
$_SESSION['error']['name'] = "First Name is required.";
}
//whether the last name is blank
if($_POST['lastname'] == '')
{
$_SESSION['error']['lastname'] = "Last Name is required.";
}
//whether the email is blank
if($_POST['email'] == '')
{
$_SESSION['error']['email'] = "E-mail is required.";
}
else
{
//whether the email format is correct
if(preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $_POST['email']))
{
//if it has the correct format whether the email has already exist
$email= $_POST['email'];
$sql1 = "SELECT * FROM users WHERE email = '$email'";
$result1 = mysqli_query($mysqli,$sql1) or die(mysqli_error());
if (mysqli_num_rows($result1) > 0)
{
$_SESSION['error']['email'] = "This Email is already used.";
}
}
else
{
//this error will set if the email format is not correct
$_SESSION['error']['email'] = "Your email is not valid.";
}
}
//whether the username is blank
if($_POST['username'] == '')
{
$_SESSION['error']['username'] = "User Name is required.";
}
//whether the pharmacy is blank
if($_POST['pharmacy'] == '')
{
$_SESSION['error']['pharmacy'] = "Pharmacy Name is required.";
}
//whether the The RX30 Lincence is blank
if($_POST['rx30lincence'] == '')
{
$_SESSION['error']['rx30lincence'] = "RX30 Lincence Name is required.";
}
function randomPassword() {
$alphabet = "abcdefghijklmnopqrstuwxyzABCDEFGHIJKLMNOPQRSTUWXYZ0123456789";
$pass = array(); //remember to declare $pass as an array
$alphaLength = strlen($alphabet) - 1; //put the length -1 in cache
for ($i = 0; $i < 8; $i++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass); //turn the array into a string
}
.
$rampass = randomPassword();
//if the error exist, we will go to registration form
if(isset($_SESSION['error']))
{
header("Location: regis.html.php");
exit;
}
else
{
$name = $_POST['name'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$username = $_POST['username'];
$password = md5('$rampass');
$licence = $_POST['rx30licence'];
$city = $_POST['city'];
$phone = $_POST['phone'];
$fax = $_POST['fax'];
$com_code = md5(uniqid(rand()));
$sql2 = "INSERT INTO users (name, lastname, email, username, password, licence, city, phone, fax, com_code) VALUES ('name', '$lastname', '$email', '$username', '$password', '$licence', '$city', '$phone', '$fax', '$com_code')";
$result2 = mysqli_query($mysqli,$sql2) or die(mysqli_error());
if($result2)
{
$to = $email;
$subject = "Confirmation from Ontime Soft inc to $username";
$header = "Ontime Soft inc: Confirmation from Ontime Soft inc";
$message = "your password is $rampass. rn";
$message = "Please click the link below to verify and activate your account. rn";
$message .= "http://www.rx30pr.com/confirm.php?passkey=$com_code";
$sentmail = mail($to,$subject,$message,$header);
if($sentmail)
{
echo "Your Confirmation link and password Has Been Sent To Your Email Address.";
}
else
{
echo "Cannot send Confirmation link to your e-mail address";
}
}
}
}
?>
当未设置$\u POST['name']
时,会出现通知,因此您可以使用:
if (isset($_POST['name']))
{
if ($_POST['name'] == '')
{
$_SESSION['error']['name'] = "First Name is required.";
}
}
您错过了输入的名称
,使用了错误的类型
使用type=“text”
缺少输入名称
将无法获取您的数据,并且没有type=“pharmacy”
等等
<div class="form-group">
<input type="text" name="pharmacy" class="form-control" id="pharmacy" placeholder="Pharmacy Name">
</div>
<div class="form-group">
<input type="text" name="rx30licence" class="form-control" id="rx30licence" placeholder="RX30 Licence">
</div>
<div class="form-group">
<input type="text" name="city" class="form-control" id="city" placeholder="City">
</div>
<div class="form-group">
<input type="text" name="phone" class="form-control" id="phone" placeholder="Phone#">
</div>
<div class="form-group">
<input type="text" name="fax" class="form-control" id="fax" placeholder="Fax#">
</div>
<span class="input-group-btn">
<input name="submit" type="submit" value="Submit"/>
</span>
</div>
这些错误的第一个解决方法是使用@markm所说的打印($\u POST)
还可以在您的条件中使用echo
,检查特定条件是否正在执行print\r($\u POST)代码>是我要开始的地方。请确保在所有输入框中指定名称。例如,您在这里遗漏的姓名标签将是您在isset中使用的和是什么?只需使用print\r($\u POST)将表单内容发布到的页面中的代码>。
<div class="form-group">
<input type="text" name="pharmacy" class="form-control" id="pharmacy" placeholder="Pharmacy Name">
</div>
<div class="form-group">
<input type="text" name="rx30licence" class="form-control" id="rx30licence" placeholder="RX30 Licence">
</div>
<div class="form-group">
<input type="text" name="city" class="form-control" id="city" placeholder="City">
</div>
<div class="form-group">
<input type="text" name="phone" class="form-control" id="phone" placeholder="Phone#">
</div>
<div class="form-group">
<input type="text" name="fax" class="form-control" id="fax" placeholder="Fax#">
</div>
<span class="input-group-btn">
<input name="submit" type="submit" value="Submit"/>
</span>
</div>