如何将数据插入mysql数据库

 收藏

我尝试使用以下代码插入数据,但实际上我不知道如何获得结果以及代码中的问题是什么,我尝试首先构建表单,然后编写插入查询并将其发送到新表格,请提供任何帮助:另外,我现在遇到以下错误:

注意:未定义的索引:第11行的C:\ xampp \ htdocs \ ers \ test.php中的服务

注意:未定义的索引:第12行的C:\ xampp \ htdocs \ ers \ test.php中的标题

注意:未定义的索引:第13行的C:\ xampp \ htdocs \ ers \ test.php中的RootCause

注意:未定义的索引:第14行的C:\ xampp \ htdocs \ ers \ test.php中的RiskRating

注意:未定义的索引:第15行对C:\ xampp \ htdocs \ ers \ test.php的影响

注意:未定义的索引:第16行的C:\ xampp \ htdocs \ ers \ test.php中的工作

注意:未定义的索引:第17行的C:\ xampp \ htdocs \ ers \ test.php中的可能性

注意:未定义的索引:在第18行的C:\ xampp \ htdocs \ ers \ test.php中查找

注意:未定义的索引:第19行在C:\ xampp \ htdocs \ ers \ test.php中的含义

注意:未定义的索引:在第20行的C:\ xampp \ htdocs \ ers \ test.php中的建议错误:无法添加或更新子行:外键约束失败(ers_1.findings,CONSTRAINTfinders_ibfk_15 FOREIGN KEY(ServiceType_ID)参考servicetype_lookup(ServiceType_ID)开更新,不执行操作 _____________________________________________________________________________________________________ 这是我的代码:

<html>
<body>
<?php
$con = mysql_connect("localhost","root","123");
error_reporting(0); 
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

?>

<form method="post"  action="test.php">
<fieldset>
<legend>Insert New Data </legend>
<p> Service Name : 
<select name="Services">
<option value="select"> -Select- </option>
<option value="architecture review">Architecture Review</option>
<option value="internal penetration testing">Internal Penetration Testing</option>
<option value="network component review">Network Component Review</option>
<option value="database review">Database Review</option>
<option value="wireless network">Wireless Network</option>
<option value="operating system review">Operating System Review</option>
<option value="web application">Web Application</option>
<option value="external penetration testing">External Penetration Testing</option>
</select>

</p>
<form method="post" action="test.php">
Ref : <input type="text" name="ref" /><br />
Title : <input type="text" name="title" /><br />
Risk Rating : 
<select name="RiskRating">
<option value="select"> -Select- </option>
<option value="High">High</option>
<option value="Medium">Medium</option>
<option value="Low">Low</option>
</select><br />
Root Cause : 
<select name="RootCause">
<option value="select"> -Select- </option>
<option value="access control">Access Control</option>
<option value="configuration management">Configuration Management</option>
<option value="patch management">Patch Management</option>
<option value="patch management">Certificate Management</option>

<option value="patch management">Password Management</option>

<option value="patch management">Audit Trail and Security Logs Management</option>

<option value="service deployment">Network Management</option>
</select><br />
Impact :
<select name="impact">
<option value="select"> -Select- </option>
<option value="high"> Major </option>
<option value="moderate"> Moderate </option>
<option value="low"> Minor </option>
</select><br />
Likelihood :
<select name="likelihood">
<option value="select"> -Select- </option>
<option value="possible"> Likely </option>
<option value="impossible">Possible</option>
<option value="definite"> Moderate </option>
<option value="definite"> Rare </option>
</select><br/>
Efforts : 
<select name="Efforts">
<option value="select"> -Select- </option>
<option value="possible"> Significant </option>
<option value="impossible">Moderate </option>
<option value="definite"> Intermediate </option>
<option value="definite"> Simple </option>
</select><br/>
Finding : <br/>
<TEXTAREA NAME="Finding" COLS=100 ROWS=10> 
回复
  • 第五以南 回复

    这是我的test.php

      <?php
    $con = mysql_connect("localhost","root","mevooo");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("ers_1", $con);
    $sql="INSERT INTO findings (Finding_ID, ServiceType_ID, Title, RootCause_ID, RiskRating_ID, Impact_ID, Efforts_ID, Likelihood_ID, Finding,Implication,  Recommendation, Report_ID) VALUES (
        '1',
        '$_POST[Services]',
        '$_POST[title]',
        '$_POST[RootCause]',
        '$_POST[RiskRating]',
        '$_POST[impact]',
        '$_POST[Efforts]',
        '$_POST[likelihood]',
        '$_POST[Finding]',
        '$_POST[Implication]',
        '$_POST[Recommendation]',
        '1'
        )";
    
    if (!mysql_query($sql,$con))
      {
      die('Error: ' . mysql_error());
      }
    echo "1 record added";
    
    mysql_close($con);
    ?> 
    <input type="button" value="HOME" onclick="location='insert_Data.php'">
    

  • 忧郁逗比 回复

    正如Squidge所说,您的表单不完整,因此请以标记结束表单。同时向我们展示test.php

  • 苏浅蓝 回复

    where is your SQL statement?
    What uis the content of test.php?

    您的表格不完整,加上表格中有一张表格。我不相信这是可行的

  • eut 回复

    抱歉,上班了:)

    我建议您将$ _POST数据提取出来:

    <?php
    $con = mysql_connect("localhost","root","mevooo");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }
    else
    {
    $services = $_POST['Services'];
    $title = $_POST['title'];
    $rootcause = $_POST['RootCause'];
    $risk = $_POST['RiskRating'];
    $impact = $_POST['impact'];
    $efforts = $_POST['Efforts'];
    $likelihood = $_POST['likelihood'];
    $finding = $_POST['Finding'];
    $implic = $_POST['Implication'];
    $recom = $_POST['Recommendation'];
    mysql_select_db("ers_1", $con);
    $sql="INSERT INTO findings (Finding_ID, ServiceType_ID, Title, RootCause_ID, RiskRating_ID, Impact_ID, Efforts_ID, Likelihood_ID, Finding,Implication, Recommendation, Report_ID) VALUES ( 1, '$services','$title','$rootcause','$risk','$impact','$efforts','$likelihood','$finding','$implic','$recom', 1 )";
    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    else{
    echo "1 record added";
    }
    }
    mysql_close($con);
    ?>
    <input type="button" value="HOME" onclick="location='insert_Data.php'">
    

  • 柯南 回复

    请为我的问题紧急答复..