0

I'm making a form for some project. The problem is when the user enter their data using the field and then submit, the input not keep in the database. Also when clicking submit the direct page show blank empty page even the connection test also not showing. I'm using almost similar code for other project and it work except for this. below is my code:

 <?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>

Can anybody tell me what the error or maybe some solution. Thanks

Nexz
  • 93
  • 1
  • 10

3 Answers3

1

just use or die after mysqli_query

 mysqli_query($link,$asas)or die ('Unable to execute query. '. mysqli_error($link));

you will get to know what is the actual problem

Juned Ansari
  • 5,035
  • 7
  • 56
  • 89
1

I think you are having problem in insert query, please check this:

$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";

Write this kind.

thank you

Therichpost
  • 1,759
  • 2
  • 14
  • 19
1
 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>