2011-09-01 59 views
0

我试图让用户将YouTube视频URL上传到数据库,但想检查URL是否已被使用。当表格填写完成(通过if语句检查)时,它会继续上传文件,但首先会检查函数(vid)是否已经上传。当我尝试代码时,出现错误:重复的检查器不工作

mysql_select_db(): supplied argument is not a valid MySQL-Link resource in /home/content/95/8201295/html/dialog/youtube-up.php on line 76

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/95/8201295/html/dialog/youtube-up.php on line 78

Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/content/95/8201295/html/dialog/youtube-up.php on line 79 Video SUbmited

有人可以帮忙,这是我的代码。感谢您的帮助。

<?php require_once('../Connections/Main.php'); 

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
    $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
    } 

    $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break;  
    case "long": 
    case "int": 
     $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
     break; 
    case "double": 
     $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
     break; 
    case "date": 
     $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
     break; 
    case "defined": 
     $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
     break; 
    } 
    return $theValue; 
} 
} 

mysql_select_db($database_Main, $Main); 
$query_youtube = "SELECT video_id FROM youtube"; 
$youtube = mysql_query($query_youtube) or die(mysql_error()); 
$row_youtube = mysql_fetch_assoc($youtube); 
$totalRows_youtube = mysql_num_rows($youtube); 

$editFormAction = $_SERVER['PHP_SELF']; 
if (isset($_SERVER['QUERY_STRING'])) { 
    $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); 
} 
function vid ($vid) { 
$SQL = "SELECT * FROM youtube WHERE video_id = '".$vid."'"; 
$result = mysql_query($SQL, $Main); 
$num_rows = mysql_num_rows($result); 
if ($num_rows > 0) { 
$errorMessage = "Video already taken"; 
echo($errorMessage); 
return false; 
} 
else { 
    echo('Video SUbmited'); 
    return true; 
} 
    } 
    $pieces = explode("=", $_POST['url']); 
    $Ndone = $pieces[1]; 
    $pieces = explode("&", $Ndone); 
    $done = $pieces[0]; 
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "youtube")) { 
    if(vid($done)) { 
     $insertSQL = sprintf("INSERT INTO youtube (video_id) VALUES (%s)", 
         GetSQLValueString($done, "text")); 

     $Result1 = mysql_query($insertSQL, $Main) or die(mysql_error()); 
    } 
    } 
?> 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> 
<title>Untitled Document</title> 
<script src="../SpryAssets/SpryValidationTextField.js" type="text/javascript"></script> 
<link href="../SpryAssets/SpryValidationTextField.css" rel="stylesheet" type="text/css" /> 
</head> 
<style type="text/css"> 
.text_box { 
    text 
    font-size: 9px; 
    color: #000; 
    } 
</style> 
<body> 

    <form action="<?php echo $editFormAction; ?>" name="youtube" height="100px" method="POST" id="youtube"> 
    <span id="url"> 
    <input type="text" class="text_box" value="type in url of video " name="url" id="url2" /> 
    <span class="textfieldRequiredMsg">A value is required.</span><span class="textfieldInvalidFormatMsg">Invalid format.</span></span> 
    </input> 
    <input type="submit"> 
    <input type="hidden" name="MM_insert" value="youtube" /> 
    </p> 
    </input> 
    </form> 
    <?php ?> 
<script type="text/javascript"> 
var sprytextfield1 = new Spry.Widget.ValidationTextField("url", "url", {validateOn:["blur"]}); 
</script> 
</body> 
</html> 
<?php 
mysql_free_result($youtube); 
?> 

回答

0

您提供的代码不包含错误。由于某种原因,我们不知道,mysql_connect失败,从而导致你所有的错误。基本上,问题在于$ database_Main变量,如错误消息所述,它不是正确的MySQL结果资源。

你应该更多地阅读关于调试的更多信息,因为你的问题表明你对这个领域缺乏足够的知识。

+0

好的,谢谢。我是新来的PHP,大部分我使用过C和C++。再次感谢。 – user918236