php - 表单值无法输入mysql,但可以连接mysql(PHP)

标签 php mysql forms

我想自己做一个php测验,当你有满分时,你可以将你的信息输入我的数据库,但是当我填写表格并提交sumbit时。有这个错误~

注意:未定义索引:第 19 行 C:\xampp\htdocs\record.php 中的名字

注意:未定义索引:C:\xampp\htdocs\record.php 中第 19 行的 lastname

注意:C:\xampp\htdocs\record.php 第19行未定义索引:age mysql_connect.inc.php

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
//資料庫設定
//資料庫位置
$db_server = "localhost";
//資料庫名稱
$db_name = "quiz";
//資料庫管理者帳號
$db_user = "root";
//資料庫管理者密碼
$db_passwd = "123456";

//對資料庫連線
if(!@mysql_connect($db_server, $db_user, $db_passwd))
        die("can't connect mysql");

//資料庫連線採UTF8
mysql_query("SET NAMES utf8");

//選擇資料庫
if(!@mysql_select_db($db_name))
        die("can't connect db");
?>  

记录.php

<?php  ?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
session_start();

include("mysql_connect.inc.php");

$con = mysql_connect("localhost","root","123456");


mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Peter', 'Griffin', '35')");

mysql_query("INSERT INTO Persons (FirstName, LastName, Age) 
VALUES ('Glenn', 'Quagmire', '33')");

$sql="INSERT INTO Persons (FirstName, LastName, Age)
VALUES
('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

 mysql_close($con)
?>

进程.php

<html>
<head>
<style type="text/css">
#wrapper {

    width:950px;
     height:auto;
     padding: 13px;
     margin-right:auto;
     margin-left:auto;
     background-color:#fff;
}
</style>
</head>
<?php 

    $fid = $_GET['id'];

?>
<body bgcolor="#e1e1e1">

<div id="wrapper">

<center><font face="Andalus" size="5">Your Score</font></center>
<br />
<br />

<?php
    $answer1= $_POST['answerOne'];
    $answer2= $_POST['answerTwo'];
    $answer3= $_POST['answerThree'];
    $score = 0;

    if ($answer1 == "A"){$score++;}
    if ($answer2 == "B"){$score++;}
    if ($answer3 == "C"){$score++;}
    echo "<center><font face='Berlin Sans FB' size='8'>Your Score is <br> $score/3</font></center>";

?>

<br>
<br>
<Center>
<?php   
  if ($score == 3)
    { 
      echo " 
      <form action='record.php' method='post' >
       ID: <input type='text' id='firstname'/><br>
       Phone: <input type='text' id='lastname'/><br>
       E-mail: <input type='text' id='age'/><br><br>
       <input type='submit' value='Submit Data' />
      </form>  ";
    }
?>
</Center>


</div><!--- end of wrapper div --->

</body>
</html>

最佳答案

您的输入字段也需要有一个“名称”属性。

关于php - 表单值无法输入mysql,但可以连接mysql(PHP),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15919732/

相关文章:

php - 如何在 Symfony 4 中使用自定义集合

PHP websocket服务器和mysql连接

php mysql 邮政编码检查

java - 如何在 Selenium 中记录充当按钮的图像的点击事件?

mysql - 如何确定表 1 中的主键是否出现在表 2 中

PHP代码点火器;防止表单重新提交

javascript - 显示从 PHP 调用到 angularJS 站点的数据

php - mysql:优化sql查询和慢查询

php - 如何从数据库中获取 "generate"Web API?

mysql - MacOS连接本地mysql出错