PHP MySQL不更新数据库
问题描述:
我有似乎是一个语法问题,但我得到零错误。 首先,我测试了每个变量以确保它们被表单正确填充,所以这里没有问题。当“$ 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);
?>
答
我想通了感谢WPCODER指着我在正确的方向。使用:
ON DUPLICATE KEY UPDATE
发现这个伟大的参考:
你试图使用UPDATE,而不是用WHERE替换条件设置? – wpcoder
不,但它是否重要?我的替换工作在其他页面上工作得很好,直到现在,工作进展顺利。 – user3053446
尝试将SQL查询直接运行到phpmyadmin或任何其他mysql界面,以确保您的查询没有错。在你的php页面中使用echo $ sql来获得最终的sql查询并在sql界面中运行它。 – wpcoder