2017-04-05 3 views
0

일부 프로젝트의 양식을 만들고 있습니다. 문제는 사용자가 입력란을 사용하여 데이터를 입력 한 다음 입력을 데이터베이스에 보관하지 않을 때입니다. 또한 직접 제출 페이지를 클릭하면 연결 테스트도 표시되지 않는 빈 페이지가 빈 페이지로 표시됩니다. 다른 프로젝트와 거의 비슷한 코드를 사용하고 있으며이 코드는 제외됩니다.데이터가 데이터베이스에 삽입되지 않습니다.

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

아무도 말해 줄 수있는 오류 또는 어쩌면 몇 가지 솔루션 : 은 아래에있는 내 코드입니다. 감사합니다

+0

[PHP 감사합니다. 오류. Log.] (http://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings/5438125#5438125) – mkaatman

+0

제출 후이 페이지로 이동하지 않을 수도 있습니다. –

+1

@Nexz 귀하의 코드는 SQL 삽입 공격에 취약합니다. Prepared Statements 사용을 고려하십시오. http://php.net/manual/en/mysqli.prepare.php –

답변

1

단지

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

당신이 실제 문제

+0

감사합니다. 나중에 시도해 보겠습니다. – Nexz

1

난 당신이 삽입 쿼리에 문제가있는 생각이 무엇인지 알게됩니다 사용하거나 mysqli_query 후 사망,이를 확인하시기 바랍니다

$sql = "INSERT INTO MyGuests (firstname, lastname, email) 
VALUES ('John', 'Doe', '[email protected]')"; 

이 종류를 쓰십시오.

당신에게

+0

덕분에, 나중에 제안을 바탕으로 노력할 것입니다. – Nexz

+0

귀하 환영 : – Aaron

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> 
+0

감사합니다. 코드 작업. 하지만 여전히 데이터를 삽입하지 못한 이유는 모르겠습니다. – Nexz

+0

몇 가지 작은 오류가있었습니다. id 변수가 $ 기호없이 사용 된 것처럼 ('id' ! = '$ Sid') 및 세미콜론을 어딘가에 놓쳤습니다. –

관련 문제