2012-04-28 66 views
0

我的PHP腳本如下:move_uploaded_file()以腳本沒有完成

<?php 

require_once('connectvars.php'); 

$file = $_FILES['image']['name']; 
$target = GW_UPLOADPATH . $file; 

if (move_uploaded_file($_FILES['image']['tmp_name'], $target)) { 
    $dbc = mysqli_connect(DB_HOST, DB_UN, DB_PW, DB_NAME) or die('Error connecting to the MySQL server'); 

    $title = mysqli_real_escape_string($dbc, trim($_POST['title'])); 
    $description = mysqli_real_escape_string($dbc, trim($_POST['content'])); 
    $host = mysqli_real_escape_string($dbc, trim($_POST['host'])); 
    $duration = mysqli_real_escape_string($dbc, trim($_POST['duration'])); 
    $sn1 = mysqli_real_escape_string($dbc, trim($_POST['link1'])); 
    $sn2 = mysqli_real_escape_string($dbc, trim($_POST['link2'])); 
    $sn3 = mysqli_real_escape_string($dbc, trim($_POST['link3'])); 
    $sn4 = mysqli_real_escape_string($dbc, trim($_POST['link4'])); 
    $sn5 = mysqli_real_escape_string($dbc, trim($_POST['link5'])); 

    $query = "INSERT INTO dyhamb (title, description, host, duration, file, sn1, sn2, sn3, sn4, sn5) VALUES ('$title', '$description', '$host', '$duration', '$file', '$sn1', '$sn2', '$sn3', '$sn4', '$sn5')"; 
    $result = mysqli_query($dbc, $query); 

    if (!$result) { 
     echo 'failed'; 
    } else { 
     echo 'success'; 
    } 

    mysqli_close($dbc); 
} 
?> 

當我跑我收到「失敗」的腳本返回,我不明白爲什麼。 $dbc$query似乎都很好,因此不確定爲什麼$result未定義。

回答

3
if ($result === FALSE) { 
    echo mysqli_error($dbc); 
} else { 
    echo mysqli_affected_rows($dbc); 
} 

另外

$的MySQL -u根-pmyPassWord DB_NAME

>從dynamb選擇標題;

確認某物正在進入數據庫。

+0

你的片段指向我一個重複的數據庫條目,我忽略了。謝謝。 – Ryan 2012-04-28 14:46:52

+0

很高興能幫到你! – 2012-04-28 20:26:22

2

嘗試查詢後添加or die(mysqli_error());

$result = mysqli_query($dbc, $query) or die(mysqli_error()); 

這可能給你一個線索什麼錯與查詢。

+0

哈哈,你打我吧:) – 2012-04-28 14:39:24