2017-10-12 120 views
-2

我有似乎是一個語法問題,但我得到零錯誤。 首先,我測試了每個變量以確保它們被表單正確填充,所以這裏沒有問題。當「$ RespondentOrPetitioner」標有「R」或「P」,應該用這個來將數據添加到我的MySQL數據庫:PHP MySQL不更新數據庫

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)); 
} 

然而,這不更新DB這些字段「RespondentFirstName,RespondentLastName ,請願者姓名,請願者姓名,請願者姓名,「和」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替換條件設置? – wpcoder

+0

不,但它是否重要?我的替換工作在其他頁面上工作得很好,直到現在,工作進展順利。 – user3053446

+0

嘗試將SQL查詢直接運行到phpmyadmin或任何其他mysql界面,以確保您的查詢沒有錯。在你的php頁面中使用echo $ sql來獲得最終的sql查詢並在sql界面中運行它。 – wpcoder

回答