這是我的代碼:PHP MySQL的問題(if語句可是沒有效果)
if ((isset($_POST['vidcode'])) && (strlen(trim($_POST['vidcode'])) > 0)) {$vidcode = stripslashes(strip_tags($_POST['vidcode']));} else {$vidcode = 'Invalid URL';};
if ((isset($_POST['vidtitle'])) && (strlen(trim($_POST['vidtitle'])) > 0)) {$vidtitle = stripslashes(strip_tags($_POST['vidtitle']));} else {$vidtitle = 'No Title';};
$vidcode = str_replace('"', '', $vidcode);$vidcode = str_replace("'", "", $vidcode);$vidtitle = str_replace('"', '', $vidtitle);$vidtitle = str_replace("'", "", $vidtitle);
$db_handle = mysql_connect($server, $user_name, $password);$db_found = mysql_select_db($database, $db_handle);
$SQL = "SELECT status FROM youtube2mp3 WHERE videocode = '$vidcode' ";$result = mysql_query($SQL); [BUGFIX:Added]$row = mysql_fetch_assoc($result);[/BUGFIX]
if(mysql_num_rows($result) != false){
// Add to DB & Set Status
$SQL = "UPDATE youtube2mp3 SET status='Download Complete' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
[BUGFIX:Removed]
// Get Data into variable
$row = mysql_fetch_assoc($result);
[/BUGFIX]
// Check if its been processed
if (strcasecmp($row['status'], "Done") != 0){
// Add to DB & Set Status
$SQL = "UPDATE youtube2mp3 SET status='Initializing Conversion' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
$filename = $vidcode.'.mp4';
if (!file_exists($filename) && !filesize($filename) >= 10000) {
$SQL = "UPDATE youtube2mp3 SET status='Invalid' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
} else {
$SQL = "UPDATE youtube2mp3 SET status='Converting' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
//convert file
exec('ffmpeg -i '.escapeshellarg($vidcode).'.mp4 -ab 156 -f mp3 '.escapeshellarg($vidtitle).'.mp3 2>&1');
$SQL = "UPDATE youtube2mp3 SET status='Zipping' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
// Zip it up
exec('zip "zips/'.$vidcode.'.zip" "'.$vidtitle.'.mp3"');
//delete files
//unlink($vidcode.'.mp4');
unlink($vidtitle.'.mp3');
$SQL = "UPDATE youtube2mp3 SET status='Done' WHERE videocode='$vidcode'";
$result = mysql_query($SQL);
};
};
};
mysql_close($db_handle);
右鍵僅供參考 - 這是我太傻了!我重新使用了$ result,這給出了意想不到的結果請參閱上面代碼中的[BUGFIX] ...
mysql_fetch_array默認MYSQL_BOTH作爲結果類型,因此將包括數值陣列以及締陣列。雖然不知道,似乎不是問題。 – Suroot 2011-06-16 22:04:20