我有一个看起来像语法问题,但我得到零错误。 首先,我测试了每个变量,以确保它们被表单正确填充,因此没有问题。当“$ RespondentOrPetitioner”标记为“r”或“p”时,它应该使用以下内容将数据添加到我的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));
}
但是,这并不是为这些字段更新数据库“RespondentFirstName,RespondentLastName,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 :(得分:0)
我想通了WPCODER指出我正确的方向。使用:
ON DUPLICATE KEY UPDATE
找到了这个很棒的参考资料: