2017-10-12 3 views
-2

構文の問題のように思えますが、エラーが発生しています。 まず、各変数をフォームで正しく入力しているかどうかをテストしました。問題はありません。 「$ RespondentOrPetitioner」が「R」または「P」でマークされている場合には、これを使用して、私のMySQLデータベースにデータを追加する必要があります。PHP MySQLがDBを更新していない

if ($RespondentOrPetitioner == "p") { 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, PetitionerFirstName, PetitionerLastName, RespondentFirstName, RespondentLastName, RespondentAttorneyFullName, PetitionerAttorneyFullName) 
     VALUES ('$CaseNumber','$PetitionerFirstName', '$PetitionerLastName', '$RespondentFirstName', '$RespondentLastName','$RespondentAttorneyFullName','$AttorneyFullName')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

しかし、これは「これらのフィールドにRespondentFirstName、RespondentLastNameをDBを更新していません、PetitionerFirstName、PetitionerLastName、PetitionerAttorneyFullName "、および" RespondentAttorneyFullName "が含まれます。

小さい$ sql文を別のファイルにコピー/貼り付けしようとしましたが、うまくいきませんでした。なぜそれが私の文書ではうまくいかないのですか?他のすべてのMYSQLコードはこのドキュメントでは動作しますが、 "IF"ステートメントの内部にある2は動作しません。私はこれを理解しようと時間を費やして、複数のPHP構文チェッカーで実行しましたが、私はまだこれを理解できません。どんな助けもありがとうございます。ここで

が全体のコードです:

<?php 
$servername = "99.99.99.99"; 
$username = "darling"; 
$password = "****"; 
$dbname = "alkouric_darling"; 
$conn = new mysqli($servername, $username, $password, $dbname); 

// Check connection 
if ($conn->connect_error) { 
    die("Connection failed: " . $conn->connect_error); 
} 

// enter San Bernardino court info 
if ($CourtCounty == "San Bernardino") { 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, CourtCounty, CourtStreetAddress, CourtMailingAddress, CourtCity, CourtZip, CourtBranchName) 
      VALUES ('$CaseNumber', 'San Bernardino', '351 N. Arrowhead Ave', '351 N. Arrowhead Ave', 'San Bernardino', '92415-0245', 'Family Law')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

// enter Los Angeles court info 
if ($CourtCounty == "Los Angeles") { 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, CourtCounty, CourtStreetAddress, CourtMailingAddress, CourtCity, CourtZip, CourtBranchName) 
      VALUES ('$CaseNumber','Los Angeles', '351 N. Arrowhead Ave', '351 N. Arrowhead Ave', 'San Bernardino', '92415-0245', 'Family Law')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

// enter Orange court info 
if ($CourtCounty == "Orange") { 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, CourtCounty, CourtStreetAddress, CourtMailingAddress, CourtCity, CourtZip, CourtBranchName) 
      VALUES ('$CaseNumber','Orange', '341 The City Drive', '341 The City Drive ', 'Orange', '92868-3209 ', 'Family Law')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

// enter Respondent/Petitioner Information 
if ($RespondentOrPetitioner == "p") { 
    echo "<b>Respondent/Petitioner Info</b><br>"; 
    echo "Petitioner (you): ".$PetitionerFirstName." ".$PetitionerLastName; 
    echo "<br>Attorney(yours): ".$AttorneyFullName; 
    echo "<br>Respondent: ".$RespondentFirstName." ".$RespondentLastName; 
    echo "<br>Attorney (theirs): ".$RespondentAttorneyFullName; 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, PetitionerFirstName, PetitionerLastName, RespondentFirstName, RespondentLastName, RespondentAttorneyFullName, PetitionerAttorneyFullName) 
      VALUES ('$CaseNumber','$PetitionerFirstName', '$PetitionerLastName', '$RespondentFirstName', '$RespondentLastName','$RespondentAttorneyFullName','$AttorneyFullName')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

// enter Respondent/Petitioner Information 
if ($RespondentOrPetitioner == "r") { 
    echo "<b>Respondent/Petitioner Info</b><br>"; 
    echo "Petitioner: ".$PetitionerFirstName." ".$PetitionerLastName; 
    echo "<br>Attorney (theirs): ".$PetitionerAttorneyFullName; 
    echo "<br>Respondent(you): ".$RespondentFirstName." ".$RespondentLastName; 
    echo "<br>Attorney(yours): ".$AttorneyFullName; 
    $sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, RespondentFirstName, RespondentLastName, PetitionerFirstName, PetitionerLastName, RespondentAttorneyFullName, PetitionerAttorneyFullName) 
      VALUES ('$CaseNumber','$RespondentFirstName', '$RespondentLastName', '$PetitionerFirstName', '$PetitionerLastName','$AttorneyFullName', '$PetitionerAttorneyFullName')"; 
    mysqli_query($conn, $sql) or die(mysqli_error($conn)); 
} 

// Insert Values into Database 
$sql = "REPLACE INTO alkouric_darling.customer(CaseNumber, FirstName, LastName, AddressLine1 , AddressLine2, City , State , Zip , County, RespondentOrPetitioner, PhoneCell , PhoneHome , PhoneWork , Email , DOB, DriversLicense, Social, OtherPartyFirstName, OtherPartyLastName, OtherPartyEmail, OtherPartyAddressLine1, OtherPartyPhoneHome, OtherPartyPhoneCell, OtherPartyPhoneWork , OtherPartyDOB , OtherPartyDriversLicense , OtherPartySocial , AttorneyFullName , AttorneyFullAddress , AttorneyFirmName, AttorneyBar, AttorneyPhone , AttorneyEmail, OtherPartyAddressLine2, OtherPartyCity , Child1FirstName, Child1LastName, Child1DOB, Child1Gender, Child1AddressLine1, Child1AddressLine2, Child1City, Child1State, Child1Zip, Child1PersonLivedWith, Child1PersonLivedWithFullAddress, Child1PeriodOfResidenceFrom, Child2FirstName, Child2LastName, Child2DOB, Child2Gender, Child2AddressLine1, Child2AddressLine2, Child2City, Child2State, Child2Zip, Child2PersonLivedWith, Child2PersonLivedWithFullAddress, Child2PeriodOfResidenceFrom, OtherPartyAttorneyFullName, OtherPartyZip, OtherPartyState) 
      VALUES ('$CaseNumber', '$FirstName', '$LastName', '$AddressLine1 ', '$AddressLine2', '$City ', '$State ', '$Zip ', '$County', '$RespondentOrPetitioner', '$PhoneCell ', '$PhoneHome ', '$PhoneWork ', '$Email ', '$DOB', '$DriversLicense', '$Social', '$OtherPartyFirstName', '$OtherPartyLastName', '$OtherPartyEmail', '$OtherPartyAddressLine1', '$OtherPartyPhoneHome', '$OtherPartyPhoneCell', '$OtherPartyPhoneWork ', '$OtherPartyDOB ', '$OtherPartyDriversLicense ', '$OtherPartySocial ', '$AttorneyFullName ', '$AttorneyFullAddress ', '$AttorneyFirmName', '$AttorneyBar', '$AttorneyPhone ', '$AttorneyEmail ', '$OtherPartyAddressLine2', '$OtherPartyCity', '$Child1FirstName', '$Child1LastName', '$Child1DOB', '$Child1Gender', '$Child1AddressLine1', '$Child1AddressLine2', '$Child1City', '$Child1State', '$Child1Zip', '$Child1PersonLivedWith', '$Child1PersonLivedWithFullAddress', '$Child1PeriodOfResidenceFrom', '$Child2FirstName', '$Child2LastName', '$Child2DOB', '$Child2Gender', '$Child2AddressLine1', '$Child2AddressLine2', '$Child2City', '$Child2State', '$Child2Zip', '$Child2PersonLivedWith', '$Child2PersonLivedWithFullAddress', '$Child2PeriodOfResidenceFrom','$OtherPartyAttorneyFullName','$OtherPartyZip','$OtherPartyState')"; 
mysqli_query($conn, $sql) or die(mysqli_error($conn)); 


mysqli_close($conn); 
?> 
+0

あなたはUPDATEを使用する代わりに、WHEREで条件を置き換えるために試してみました:

ON DUPLICATE KEY UPDATE 

は、この偉大な参照を発見されましたか? – wpcoder

+0

いいえ、それは重要ですか?私の入れ替え先は他のページでうまくいき、今までは偉大な作業をしていました。 – user3053446

+0

phpmyadminまたは他のmysqlインターフェイスに直接SQLクエリを実行して、クエリに間違いがないことを確認してください。 PHPのページでecho $ sqlを使用して、最終的なSQLクエリを取得し、SQLインタフェースで実行します。 – wpcoder

答えて

関連する問題