gpt4 book ai didi

PHP MySQL问题(if语句无效)

转载 作者:行者123 更新时间:2023-11-29 14:48:17 25 4
gpt4 key购买 nike

这是我的代码:

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]...

最佳答案

不要使用SELECT *...,在查询中明确列出您的列。这样,通过查看代码就可以清楚地了解您希望从数据库中获取哪些列。另外,如果事实证明您认为存在的列不存在,那么您将在问题实际发生的阶段(在数据检索时)收到错误,而不是在代码稍后尝试使用数据。

另请注意,您使用 mysql_fetch_array ( docs ) 将返回一个数字索引的列数组。使用 mysql_fetch_assoc ( docs ) 作为关联数组。

$db_handle = mysql_connect($server, $user_name, $password);
$db_found = mysql_select_db($database, $db_handle);
$sql = '
SELECT
`status`,
`some_other_field`
FROM
`table`
WHERE
`videocode` = "'.$vidcode.'"';
$result = mysql_query($sql, $db_handle) or die('Error while performing query: '.mysql_error($db_handle));

if (mysql_num_rows($result, $db_handle) < 1) {
// you didn't get any rows back...
}

if(mysql_num_rows($result) != false){
// Get Data into variable
$row = mysql_fetch_assoc($result, $db_handle);

// Check if its been processed
if ($row['status'] != "Done"){
// CODE HERE IS STILL GETTING EXECUTED EVEN WHEN $row['status'] IS "Done"

}
}

使用此代码,如果您尝试选择的列不存在,则会收到数据库错误。

关于PHP MySQL问题(if语句无效),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6378992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com