dongnao2048 2017-05-16 10:29
浏览 68

如何从表单提交中修复PHP中的变量声明

I am creating a registration page. Here is my PHP code:

    <?php
$id = $name = $pwd = $confirm_pwd = $eamil = $phone = $dob = $region = $city = "";
$idErr = $nameErr = $passErr = $phoneErr = $emailErr = $message = $dobErr = $regionErr = $cityErr = "";
if(isset($_POST['submit'])) {
  if (empty($_POST["national_id"])) {
    $nameErr = "national id is required";
  } else {
    $id = test_input($_POST["national_id"]);
  }
  if (empty($_POST["name"])) {
    $nameErr = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
  }

  if (empty($_POST["pwd"])) {
    $passErr = "password is required";
  } else {
    $pwd = test_input($_POST["pass"]); 
  }
  /* Password Matching Validation */
if($_POST['pwd'] != $_POST['confirm_pwd']){ 
$message = 'Passwords should be same<br>'; 
}
else {
$pwd = test_input($_POST["pwd"]);   
}
 if (empty($_POST["email"])) {
    $emailErr = "email is required";
  } else {
    $email = test_input($_POST["email"]); 
  }    

  if (empty($_POST["phone"])) {
    $phoneErr = "phone is required";
  } else {
    $phone = test_input($_POST["phone"]);
  }
  if (empty($_POST["date_of_birth"])) {
    $dobErr = "date of birth is required";
  } else {
    $dob = test_input($_POST["date_of_birth"]);
  }
  if (empty($_POST["region"])) {
    $regionErr = "region is required";
  } else {
    $region = test_input($_POST["region"]);
  }
  if (empty($_POST["city"])) {
    $cityErr = "city is required";
  } else {
    $phone = test_input($_POST["city"]);
  }
}

else{
$con = new mysqli("localhost","root","","seis") or die(mysql_error());
$id = $_POST["national_id"];
$name = $_POST["name" ];
$pwd = md5($_POST["pwd" ]);
$email = $_POST["email" ];
$phone = $_POST["phone" ];
$dob = $_POST["date_of_birth" ];
$region = $_POST["region" ];
$city = $_POST["city" ];

$national_id = trim($id);
$cust_name  = trim($name);
$cust_pwd = trim($pwd);
$cust_email = trim($email);
$cust_phone = trim($phone);
$cust_dob = trim($dob);
$cust_region = trim($region);
$cust_city = trim($city);
$processvalue = "Insert INTO Registration
              VALUES ('$national_id' ,'$cust_name', '$cust_dob' ,'$cust_email' , '$cust_pwd' , '$phone' , (select region_serial,city_serial from cities where region = '$cust_region' AND city = '$cust_city') )";


if (mysqli_query($con, $processvalue)) {

echo 'You are registered ';

} else {
   echo "error:" .mysqli_error($con);
}
}
mysqli_close($con)

?>

I am trying to insert each variable to an SQL statement, but it seems like I have a problem with variable initialization.

This is the error I get:

Notice: Undefined index: national_id in C:\xampp\htdocs\seis-new\signup.php on line 68

Notice: Undefined index: name in C:\xampp\htdocs\seis-new\signup.php on line 69

Notice: Undefined index: pwd in C:\xampp\htdocs\seis-new\signup.php on line 70

Notice: Undefined index: email in C:\xampp\htdocs\seis-new\signup.php on line 71

Notice: Undefined index: phone in C:\xampp\htdocs\seis-new\signup.php on line 72

Notice: Undefined index: date_of_birth in C:\xampp\htdocs\seis-new\signup.php on line 73

Notice: Undefined index: region in C:\xampp\htdocs\seis-new\signup.php on line 74

Notice: Undefined index: city in C:\xampp\htdocs\seis-new\signup.php on line 75 error:Table 'seis.registration' doesn't exist

  • 写回答

4条回答 默认 最新

  • dtntjwkl83750 2017-05-16 10:32
    关注

    you have to use isset() function to check variable index is set or not

    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?