首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >数据未插入到数据库中

数据未插入到数据库中
EN

Stack Overflow用户
提问于 2017-04-05 13:09:20
回答 3查看 84关注 0票数 0

我正在为某个项目制作表格。问题是,当用户使用字段输入数据然后提交时,输入内容不会保留在数据库中。另外,当单击提交时,直接页面显示为空白页面,甚至连连接测试也不显示。我在其他项目中使用了几乎类似的代码,除了这个。下面是我的代码:

代码语言:javascript
运行
复制
 <?php

    //check connection
    require 'config.php';
    if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
    }
    echo "Connected successfully";

   //asas (table name)
       $id = $_POST["Sid"]; $ic = $_POST["Sic"];
       $name = $_POST["Snp"]; $jant = $_POST["J1"];
       $trum = $_POST["Chr"];$tbim = $_POST["Chp"];
       $mel = $_POST["Sem"]; $arum = $_POST["Ar"];
       $asum = $_POST["As"];

  //institusi
       $thp = $_POST["T1"]; $uni = $_POST["Sis"];
       $bid = $_POST["tpe"];$Aint = $_POST["Ai"];

 //industri
      $bip = $_POST["bid"];$bik = $_POST["B1"];
      $tem = $_POST["te"];$mula = $_POST["tm"];
      $tamm = $_POST["tt"]; $res = $_POST["fileToUpload1"];
      $tran = $_POST["fileToUpload2"];$keb = $_POST["fileToUpload3"];


    $link = mysqli_connect($h,$u,$p,$db);

    if('id' != '$Sid'){
    $asas = "insert into asas Values ('$id','$ic','$name','$jant','$trum','$tbim','$mel','$arum','$asum')";
    $inst = "insert into institusi Values ('$thp','$uni','$bid','$Aint')";
    $indr = "insert into industri Values ('$bip','$bik','$tem','$mula','$tamm','$res','$tran','$keb')";

      mysqli_query($link,$asas);
      mysqli_query($link,$inst);
      mysqli_query($link,$indr);
      mysqli_close($link);
     }
      else
     {
     echo "failed"
     }
    ?>
   <b>Register complete</b>

有没有人能告诉我错误是什么,或者是一些解决方案。谢谢

EN

回答 3

Stack Overflow用户

发布于 2017-04-05 13:16:31

要么使用,要么在mysqli_query之后死掉

代码语言:javascript
运行
复制
 mysqli_query($link,$asas)or die ('Unable to execute query. '. mysqli_error($link));

你将会知道真正的问题是什么。

票数 1
EN

Stack Overflow用户

发布于 2017-04-05 13:43:26

我认为您在插入查询时遇到问题,请检查以下内容:

代码语言:javascript
运行
复制
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

写这样的。

谢谢

票数 1
EN

Stack Overflow用户

发布于 2017-04-05 14:03:05

代码语言:javascript
运行
复制
 there are few issues with the code like variable id was used without $     
 and need to use die method with mysqli_query() function to check for 
 errors, please check below improved codes, it may help you - 

<?php
    //check connection
    require 'config.php';
   if (isset($_POST)) {
 //asas (table name)
$id   = $_POST["Sid"];
$ic   = $_POST["Sic"];
$name = $_POST["Snp"];
$jant = $_POST["J1"];
$trum = $_POST["Chr"];
$tbim = $_POST["Chp"];
$mel  = $_POST["Sem"];
$arum = $_POST["Ar"];
$asum = $_POST["As"];
//institusi
$thp  = $_POST["T1"];
$uni  = $_POST["Sis"];
$bid  = $_POST["tpe"];
$Aint = $_POST["Ai"];
//industri
$bip  = $_POST["bid"];
$bik  = $_POST["B1"];
$tem  = $_POST["te"];
$mula = $_POST["tm"];
$tamm = $_POST["tt"];
$res  = $_POST["fileToUpload1"];
$tran = $_POST["fileToUpload2"];
$keb  = $_POST["fileToUpload3"];
}
$link = mysqli_connect($h, $u, $p, $db);
if (!$link) {
 die("Connection failed: " . mysqli_connect_error());
}
//   if('id' != '$Sid'){
 if ($id != '$Sid') {
 $asas = "insert into asas Values 
 ('$id','$ic','$name','$jant','$trum','$tbim','$mel','$arum','$asum')";
 $inst = "insert into institusi Values ('$thp','$uni','$bid','$Aint')";
 $indr = "insert into industri Values 
 ('$bip','$bik','$tem','$mula','$tamm','$res','$tran','$keb')";
 if (mysqli_query($link, $asas)) {
    echo "records inserted";
 } else {
    echo "failed".mysqli_error($link) ;
 }
 if (mysqli_query($link, $inst)) {
    echo "records inserted";
 } else {
    echo "failed".mysqli_error($link) ;
 }
 if (mysqli_query($link, $indr)) {
    echo "records inserted";
 } else {
    echo "failed".mysqli_error($link) ;
 }
}
 mysqli_close($link);
?>
 <b>Register complete</b>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43222275

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档