2017-02-04 339 views
-1

我得到一個解析錯誤,下面的代碼。我已經搜索,但無法找到答案。

錯誤:

Parse error: syntax error, unexpected '$aircrafttype' (T_VARIABLE) in dbinput.php on line 58 

下面是代碼:

<?php 


    if (isset($_POST['submit'])) { 

    $data_missing = array(); 

    if(empty($_POST['airline'])) { 
     $data_missing[] = 'Flygbolag'; 
    } else { 
     $airline = $_POST['airline']; 
    } 

    if(empty($_POST['registration'])) { 
     $data_missing[] = 'Registrering'; 
    } else { 
     $registration = $_POST['registration']; 
    } 

    if(empty($_POST['msn'])) { 
     $data_missing[] = 'MSN'; 
    } else { 
     $msn = $_POST['msn']; 
    } 

    if(empty($_POST['aircrafttype'])) { 
     $data_missing[] = 'Flygplanstyp'; 
    } else { 
     $aircrafttype = $_POST['aircrafttype']; 
    } 

    if(empty($_POST['enginedata'])) { 
     $data_missing[] = 'Motorer'; 
    } else { 
     $enginedata = $_POST['enginedata']; 
    } 

    if(empty($_POST['loc'])) { 
     $data_missing[] = 'Plats'; 
    } else { 
     $loc = $_POST['loc']; 
    } 
    } 

    if (empty($data_missing)) { 
    require_once('../dbconnect.php'); 

    $query = "INSERT INTO Aircraft_spotted VALUES (?, ?, ?, ?, ?, ?)"; 

    $stmt = mysqli_prepare($conn, $query); 
    mysqli_stmt_bind_param($stmt, "ssisss", $airline, $registration, $msn, $aircrafttype, $enginedata, $loc); 

    mysqli_stmt_execute($stmt); 

    $affected_rows = mysqli_stmt_affected_rows($stmt); 

    if ($affected_rows == 1) { 
     echo "Aircraft entered to database"; 
     mysqli_stmt_close($stmt); 
     mysqli_close($conn); 
    } else { 
     echo "Error occured: " . mysqli_error(); 
    } 

    } else { 
    echo "You need to enter the following data: <br />"; 

    foreach ($data_missing as $missing) { 
     echo "$missing<br />"; 

     echo "string"; 
    } 
    } 

?> 

我任何答覆感謝或與問題有所幫助。非常感謝!非常感謝!

塞繆爾

回答

0

檢查,如果您的$_POST['aircrafttype']存在通過print_r($_POST)

也許你沒有設置這個或aircrafttype字段沒有送到郵局。試試:

if (isset($_POST['submit'])) { 

    $data_missing = array(); 

    if(empty($_POST['airline']) || !isset($_POST['airline'])) { 
     $data_missing[] = 'Flygbolag'; 
    } else { 
     $airline = $_POST['airline']; 
    } 

    if(empty($_POST['registration']) || !isset($_POST['registration'])) { 
     $data_missing[] = 'Registrering'; 
    } else { 
     $registration = $_POST['registration']; 
    } 

    if(empty($_POST['msn']) || !isset($_POST['msn'])) { 
     $data_missing[] = 'MSN'; 
    } else { 
     $msn = $_POST['msn']; 
    } 

    if(empty($_POST['aircrafttype']) || !isset($_POST['aircrafttype'])) { 
     $data_missing[] = 'Flygplanstyp'; 
    } else { 
     $aircrafttype = $_POST['aircrafttype']; 
    } 

    if(empty($_POST['enginedata']) || !isset($_POST['enginedata'])) { 
     $data_missing[] = 'Motorer'; 
    } else { 
     $enginedata = $_POST['enginedata']; 
    } 

    if(empty($_POST['loc']) || !isset($_POST['loc'])) { 
     $data_missing[] = 'Plats'; 
    } else { 
     $loc = $_POST['loc']; 
    } 
    } 
+0

好的。這是我的結果。我甚至將輸入字段的名稱更改爲「type」。 Array([airline] => Test [registration] => t [msn] => 39 [type] => a94 [enginedata] => 2 x 459 [loc] => Test [submit] => ) –

+0

@SamuelAndersson更新了我的答案 –

相關問題