2017-10-12 5 views
-2

J'ai un problème de syntaxe, mais je reçois zéro erreur. Tout d'abord, j'ai testé chaque variable pour m'assurer qu'elles étaient correctement remplies par le formulaire, donc il n'y a pas de problème. Quand « $ RespondentOrPetitioner » est marquée par « r » ou « p » il faut ajouter les données à ma base de données MySQL en utilisant ceci:PHP MySQL ne pas mettre à jour la base de données

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

Cependant, ce n'est pas mise à jour de la base de données pour ces champs « RespondentFirstName, RespondentLastName , PetitionerFirstName, PetitionerLastName, PetitionerAttorneyFullName, "et" RespondentAttorneyFullName. "

J'ai essayé de copier/coller juste la petite déclaration $ sql dans un fichier séparé et cela a très bien fonctionné, alors pourquoi cela ne fonctionnera-t-il pas sur mon document? Tous les autres codes MYSQL fonctionnent dans ce document, mais les 2 qui se trouvent dans les instructions "IF" ne fonctionnent pas. J'ai passé des heures à essayer de comprendre cela et l'ai passé à travers plusieurs vérificateurs de syntaxe PHP et je n'arrive toujours pas à le comprendre, toute aide serait appréciée.

Voici le code complet:

<?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

avez-vous essayé d'utiliser UPDATE au lieu de REPLACE avec condition WHERE? – wpcoder

+0

Non, mais devrait-il importer? Mon remplacement dans fonctionne très bien sur d'autres pages et fonctionnait très bien jusqu'à maintenant. – user3053446

+0

essayez d'exécuter la requête SQL directement dans phpmyadmin ou toute autre interface mysql pour être sûr que rien ne va pas avec votre requête. Utilisez echo $ sql dans votre page php pour obtenir la requête sql de fin et l'exécuter dans l'interface sql. – wpcoder

Répondre