简体   繁体   English

提交时数据不保存按有(注意:未定义索引:第 18 行 C:\\xampp\\htdocs\\CW\\register.php 中的名字

[英]Data not saving when submit is press having ( Notice: Undefined index: firstname in C:\xampp\htdocs\C.W\register.php on line 18

enter code here   
               <?php

//declare the basic variables
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "coursework";

//create connection
$link = new mysqli($servername, $username, $password, $dbname);

   if($link->connect_error){
      die ("connection failed: " . $link->connect_error);
   }


$sql = "INSERT INTO user (firstname, lastname, email, phn_number, password)                    VALUES ('".$_POST['firstname']."', '".$_POST['lastname']."',   '".$_POST['email']."', '".$_POST['phn_number']."', '".$_POST['password']."')";
 if (mysqli_query($link, $sql)){
   echo "Signed up Successfully";
 }else{
   echo "Error: Sign up Unsuccessfull $sql . " . mysqli_error($link);
 }
 //close db
 $link -> close();
  ?>

this is my PHP file code.这是我的 PHP 文件代码。 Every time I run it creats a new user but the data entered by the user doesn't save in the database.每次运行它都会创建一个新用户,但用户输入的数据不会保存在数据库中。 and an error shows up并出现错误

Notice: Undefined index: firstname in C:\xampp\htdocs\C.W\register.php on line 18
Notice: Undefined index: lastname in C:\xampp\htdocs\C.W\register.php on line 19
Notice: Undefined index: email in C:\xampp\htdocs\C.W\register.php on line 20
Notice: Undefined index: phn_number in C:\xampp\htdocs\C.W\register.php on line 21
Notice: Undefined index: password in C:\xampp\htdocs\C.W\register.php on line 22

help!!!!帮助!!!!

update your code with this one:用这个更新你的代码:

 if($link->connect_error){
  die ("connection failed: " . $link->connect_error);
  }

$sql ="INSERT INTO user (firstname, lastname, email, phn_number, password) VALUES ('Dinanath', 'Thakur', 'dina@example.com', 123456789, 'xyz')";

your html form should be in the format, update your html form:您的 html 表单应采用以下格式,更新您的 html 表单:

<p>
    <label for="firstname"> First Name: </label>
    <input type="text" name="firstname" id="firstname"> <br/> <br/>
    <label for="lastname"> Last Name: </label>
    <input type="text" name="lastname" id="lastname"> <br/> <br/>
    <label for="email"> E-mail: </label>
    <input type="text" name="email" id="email"> <br/> <br/>
    <label for="phn_number"> Phone Number: </label>
    <input type="text" name="phn_number" id="phn_number"> <br/> <br/>
    <label for="password"> Password: </label>
    <input type="text" name="password" id="password">
</p>
<input type="submit" value="Sign Up">

You might forgot to include this:你可能忘了包括这个:

form action="name_of_your_php_file.php" method="POST"表单动作=“name_of_your_php_file.php”方法=“POST”

Inserting this to the code you provided above gives us:将此插入到您上面提供的代码中,我们得到:

<form action="name_of_your_php_file.php" method="POST">
<p> <label for "firstname"> First Name: </label>
<input type="text" name"firstname" id="firstname"> <br/ > <br/ > 
<label for "lastname"> Last Name: </label> <input type="text" name"lastname" id="lastname"> <br/ > <br/ > 
<label for "email"> E-mail: </label> <input type="text" name"email" id="email"> <br/ > <br/ >
<label for "phn_number"> Phone Number: </label> <input type="text" name"phn_number" id="phn_number"> <br/ > <br/ > <label for "password"> Password: </label>
<input type="text" name"password" id="password"> </p>
<input type="submit" value="Sign Up"></form>
if($link->connect_error){

die ("connection failed: " . $link->connect_error);

}

$fname = $_POST['fname'];

$lname = $_POST['lname'];

$email = $_POST['email'];

$pno = $_POST['pno'];

$pass = $_POST['pass'];

$sql ="INSERT INTO user (firstname, lastname, email, phn_number, password)     VALUES ('$fname', '$lname', '$email', '$pno', '$pass')";

$res = mysql_query($sql);

暂无
暂无

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

相关问题 注意:未定义偏移量:1 in C:\\xampp\\htdocs\\index.php 第 5 行 - Notice: Undefined offset: 1 in C:\xampp\htdocs\index.php on line 5 注意:未定义的变量:第18行的C:\\ xampp \\ htdocs \\ mvc \\ app \\ validation \\ DForm.php中的currentValue - Notice: Undefined variable: currentValue in C:\xampp\htdocs\mvc\app\validation\DForm.php on line 18 致命错误:第 19 行在 C:\\xampp\\htdocs\\register.php 中抛出未捕获的异常“PDOException” - Fatal error: Uncaught exception 'PDOException' thrown in C:\xampp\htdocs\register.php on line 19 注意:未定义的索引:在线的C:\\ xampp \\ htdocs \\ cars \\ index1.php中的elegido - Notice: Undefined index: elegido in C:\xampp\htdocs\cars\index1.php on line PHP:注意:未定义的索引:第9行的C:\\ xampp \\ htdocs \\ vdab \\ cookies.php中的NameFilledIn - PHP : Notice: Undefined index: NameFilledIn in C:\xampp\htdocs\vdab\cookies.php on line 9 php注意:未定义的索引:第3行的C:\\ xampp \\ htdocs \\ includes \\ middle.php中的id - php Notice: Undefined index: id in C:\xampp\htdocs\includes\middle.php on line 3 PHP 注意:未定义索引:第 30 行 C:\\xampp\\htdocs\\try1.php 中的步骤 - PHP Notice: Undefined index: step in C:\xampp\htdocs\try1.php on line 30 注意:未定义的索引:第6行的C:\\ xampp \\ htdocs \\ project \\ uploads \\ upload.php中的文件 - Notice: Undefined index: file in C:\xampp\htdocs\project\uploads\upload.php on line 6 注意:未定义的索引:第15行的C:\\ xampp \\ htdocs \\ Sites \\ ooplr \\ classes \\ Validate.php中的密码? - Notice: Undefined index: password in C:\xampp\htdocs\Sites\ooplr\classes\Validate.php on line 15? 注意:未定义的索引:第3行的C:\\ xampp \\ htdocs \\ libsys \\ edit.php中的ID - Notice: Undefined index: id in C:\xampp\htdocs\libsys\edit.php on line 3
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM