2016-07-10 2 views
0

이것은 토요일을 소비했습니다. 도와주세요.한 필드에서 SQL UPDATE 문이 작동하지 않습니다.

GoDaddy 공유 계정에서 호스팅되는 MySQL 데이터베이스 테이블의 레코드를 업데이트해야하는 큰 형식이 있습니다. 양식을 제출할 때 업데이트하려고하는 18 개의 레코드가 있지만 지금까지는 17 개 밖에 없었습니다. 마지막 필드 인 "blackTowellCount"는 UPDATE 문에 포함시킬 때 문제를 일으 킵니다.

해당 필드를 SQL 문에서 제외하면 ALL 18 필드가 성공적으로 PHP 파일에 POST되고 SQL 문에 나열된 17 개가 정상적으로 업로드됩니다. blackTowellCount 필드를 포함 시키면 UPDATE가 작동을 멈추고 양식은 더 이상 PHP 양식에 데이터를 놓지 않습니다. WTF?!

거의 동일한 필드 인 "whiteTowellCount"가 잘 업데이트됨을 알 수 있습니다. 폼의

부 :

<div class="well"> 
       <div class="row"> 
       <div class="col-md-1"> 
       </div> 
       <div class="col-md-2"> 
        <label for="blackTowellCount" class="pull-right">Black Towells</label> 
       </div> 
       <div class="col-md-3"> 
         <input type="text" class="form-control" id="blackTowellCount" name="blackTowellCount" placeholder="black towell #"/> 
       </div> 
       <div class="col-md-2"> 
         <label for="whiteTowellCount" class="pull-right">White Towells</label> 
       </div> 
       <div class="col-md-3">     
        <input type="text" class="form-control" id="whiteTowellCount" name="whiteTowellCount" placeholder="white towell #"/> 
       </div> 
       <div class="col-md-1"> 
       </div> 


       </div>  
      </div> 

기능성 SQL :

$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error()); 

깨진 SQL :

$addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', blackTowellCount='".$blackTowellCount."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error()); 

.PHP 파일의 부분 : 모든 등 모든

$bathTowellCount = $_POST['bathTowellCount']; 
    $breakfastCount = $_POST['breakfastCount']; 
    $lunchCount = $_POST['lunchCount']; 
    $dinnerCount = $_POST['dinnerCount']; 
    $breakfastRestriction = $_POST['breakfastRestriction']; 
    $lunchRestriction = $_POST['lunchRestriction']; 
    $dinnerRestriction = $_POST['dinnerRestriction']; 

    $arrivalDate = $_POST['arrivalDate']; 
    $arrivalTime = $_POST['arrivalTime']; 
    $needTransport = $_POST['needTransport']; 

    $blackTowellCount = $_POST['blackTowellCount']; 
    $whiteTowellCount = $_POST['whiteTowellCount']; 

    $addIntakeSQL = mysqli_query($link,"UPDATE Act SET w9FilePath='".$w9Upload_destination."', riderFilePath='".$riderUpload_destination."', hospRiderFilePath='".$hospRiderUpload_destination."', inputFilePath='".$inputListUpload_destination."', stageFilePath='".$stagePlotUpload_destination."', backlineFilePath='".$backlineUpload_destination."', bathTowellCount='".$bathTowellCount."', breakfastCount='".$breakfastCount."', lunchCount='".$lunchCount."', dinnerCount='".$dinnerCount."', breakfastRestriction='".$breakfastRestriction."', lunchRestriction='".$lunchRestriction."', dinnerRestriction='".$dinnerRestriction."', arrivalDate='".$arrivalDate."', arrivalTime='".$arrivalTime."', needTransport='".$needTransport."', whiteTowellCount='".$whiteTowellCount."' WHERE actID='".$actID."'") or die (mysqli_error()); 

}  
+4

1. 코드가 너무 많습니다. 필요한 것을 게시하십시오. 2. 오류를 확인하지 않습니다. PHP와 MySQL은 무엇이 잘못 되었는가를 듣고 자합니다. 3. SQL 인젝션에 대해 열려 있습니다. –

+0

오류보고/시도/캐치 – Drew

+0

1. 복사 2. 어떻게하는지 모르지만, 그것. 3. 이걸 좀 더 설명 할 수 있니? 나는 단지 배우려고 노력하고있다. –

답변

1

안녕하세요 우선 코드 대신 PDO를 사용 SQL injections에게 열려 있습니다 제안했다. 두 번째 PHP는 그 기능을 당신이 할 일이 없다면 오류를 표시 할 수 있습니다. 당신이 "blackTowellCount"앞에 공간이 있었다 die(mysqli_error($link));

+0

오류보고를 사용하여 시작한 후 몇 가지 오류를 발견하고 해결했지만 문제가 계속 발생합니다. 오류는 나타나지 않지만, blackTowellCount = ' ". $ blackTowellCount."'를 SQL에 추가하면 여전히 작동하지 않습니다. 추가 전후에 오류가 없지만 이전에는 작동합니다. –

+0

Ok 일단이 blackTowellCount로 쿼리를 echo하고 쿼리를 확인한 후 phpmyadmin에서 쿼리를 실행 한 다음 phpmyadmin에서 어떤 오류가 발생했는지 확인하십시오 – user1234

0

에서와 die(mysqli_error()); 교체의 매개 변수

mysqli_error()를 부여하지 않은

또한
error_reporting(E_ALL); 
ini_set('display_errors',1); 

는 페이지의 상단에 다음 줄을 추가 데이터베이스 나는 프로그래밍이 싫어.

관련 문제