현재 사용자가 임의의 코드를 받아서 최대 3 번의 다운로드를 위해 mp3에 액세스하는 데 사용하는 다운로드 플랫폼을 개발 중입니다. 파이썬을 사용하여 임의의 코드 목록을 생성하고 관련 전자 메일 주소의 빈 열이있는 SQL 테이블로 가져오고 사용 횟수는 기본값 0으로 가져 왔습니다. 전자 메일을 특정 코드와 연결하고 카운트에 추가하기 위해 다운로드에 최대 세 번 액세스 할 수 있도록 다음 PHP 스크립트를 작성했습니다.PHP MySQL SELECT 리소스 만 반환 쿼리
$email = $_POST["email"];
$email = stripslashes($email);
$uniqueCode = $_POST["uniqueCode"];
$uniqueCode = stripslashes($uniqueCode);
// check that all fields are filled
if($uniqueCode=="" || $email=="")
apologize("Please fill out all fields.");
// check to make sure that the e-mail is valid
if (verifyEmail($email) == FALSE)
apologize("Please enter a valid e-mail address.");
// check if uniqueCode input is alphanumeric
if (verifyCode($uniqueCode) == FALSE)
apologize("Download codes are alphanumeric.");
// check to see if unique code is correct
$sql = mysql_query("SELECT * FROM wd009 where uniqueCode='$uniqueCode'");
$result = mysql_fetch_array($sql);
if($sql==FALSE)
{
apologize("Your download code is invalid. Please try again");
}
// only allow users with less than 3 downloads to proceed
else if ($result['count'] <= 3) {
if ($result['email'] == ""){
mysql_query("UPDATE wd009 SET email='$email', count=1 WHERE uniqueCode='$uniqueCode'");
apologize("added email");
}
else if ($result['email'] != $email)
apologize("different email from record!!");
else if ($result['email'] == $email){
mysql_query("UPDATE wd009 SET count=count+1 WHERE uniqueCode='$uniqueCode'");
apologize("updated the count!");
}
else
apologize("Your download code is used up!");
는 분명 내가 코드에 포함되지 않습니다 위의 일부 기능을 사용하지만 나는 그들 모두를 확인했고 그들 중 누구도 MySQL의 쿼리에 방해가 없습니다. apologize()가 사과 한 직후 종료 될 수 있습니다. 양식에 올바른 코드를 입력하면 올바르게 작동하고 SQL 데이터베이스가 업데이트됩니다. 그러나 다운로드 코드 입력이 영숫자 인 경우 양식이 문자열이 테이블에있는 특정 문자열과 일치하지 않더라도 양식을 수락합니다. 즉, mysql_query는 입력에 관계없이 리소스를 리턴한다. 데이터베이스 연결을 점검했지만 다운로드 코드가 올 바르면 테이블이 올바르게 업데이트되었으므로 문제가되지 않습니다.
내가 생각할 수있는 모든 방법으로 디버깅을 시도했으며 진정으로 당황 스럽다. 당신이 제공 할 수있는 모든 도움이 크게 감사하겠습니다!
PDO를 사용하면 좀 더 친숙해질 것입니다. 더 이상이 자원을 사용하지 않습니다. – hakre