Ich erstelle ein Formular, um Daten in die Legementtabelle und die beleuchtete Tabelle einzufügen, und auch Tabelle espace. Ich versuche, Daten in all diesen Tabellen einzufügen, wie in dem Bild verbunden sind enter image description hereFehler mit einer Fremdschlüsseleinschränkung schlägt fehl
, aber ich bin immer diese Fehlermeldung:
Warning: mysql_insert_id() expects parameter 1 to be resource, object given in F:\-- SOFTWARE\WEB-SERVER\esyphp\ep0002\data\localweb\school\buckup\BU-Projet\0008\ajoutez.php on line 88
ERROR: Could not able to execute INSERT INTO logement(Titre, AdresseLogement, Prix, NombrePerson, idTypeLogement) VALUES ('hgfrte','125669 hgfer','1236','33',''). Cannot add or update a child row: a foreign key constraint fails (`yandexd`.`logement`, CONSTRAINT `FK_Logement_idTypeLogement` FOREIGN KEY (`idTypeLogement`) REFERENCES `typedelogement` (`idTypeLogement`)) ERROR: Could not able to execute INSERT INTO lit(idLit, TypeDeLit) VALUES ('','kanape, canape'). Cannot add or update a child row: a foreign key constraint fails (`yandexd`.`lit`, CONSTRAINT `FK_Lit_idLogement` FOREIGN KEY (`idLogement`) REFERENCES `logement` (`idLogement`))
mein PHP-Code ist
if(isset($_POST['Submit'])){
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
$link = @mysqli_connect("localhost", "root", "", "yandexd");
// Check connection
if($link === false){
die("ERROR: Could not connect. " . mysqli_connect_error());
}
switch ($_POST['logm-type']) {
case "Maison":
$_POST['logm-type'] = 1;
break;
case "Appartement":
$_POST['logm-type'] = 2;
break;
case "Chambre_privée":
$_POST['logm-type'] = 3;
break;
case "Chambre_partagée":
$_POST['logm-type'] = 4;
break;
}
$sql = "INSERT INTO logement(Titre, AdresseLogement, Prix, NombrePerson, idTypeLogement)
\t VALUES ('".$_POST['logm-titre']."','".$_POST['logm-adresse']."','".$_POST['logm-prix']."','".$_POST['logm-personne']."','".$_POST['logm-type']."')";
$thelogm_id = mysql_insert_id($link);
$sql1 = "INSERT INTO espace(TypeDEspace, idLogement)
\t VALUES ('".$_POST['logm-espace']."','".$thelogm_id."')";
$sql2 = "INSERT INTO lit(TypeDeLit, idLogement)
\t VALUES ('".$_POST['logm-typelit']."','".$thelogm_id."')";
if(mysqli_query($link, $sql)){
echo "Le logement est ajouté.";
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
if(mysqli_query($link, $sql1)){
echo "Le logement est ajouté.";
} else{
echo "ERROR: Could not able to execute $sql1. " . mysqli_error($link);
}
if(mysqli_query($link, $sql2)){
echo "Le logement est ajouté.";
} else{
echo "ERROR: Could not able to execute $sql2. " . mysqli_error($link);
}
// close connection
mysqli_close($link);
}
else {
Ich versuchte alle Lösung auf Stackoverflow gefunden, b Ich kann das Problem nicht lösen
Ihr Fehler erwähnt 'mysql', während Sie' mysqli' verwenden, haben Sie das überprüft? – RST
ich verwende mysql – Bynd
Ja, Sie verwenden MySQL als Ihre Datenbank-Engine, aber mysql_insert_id() ist keine gültige Funktion für mysqli. –