I have created a form that I link with PHP. I need the foreign key number to be the same with id of another table.
There is no problem of extracting data from the form and I test this on Error Session. Also no problem with foreign key connection on the database.
However, Select statement does not work. Is it about syntax in the insert statement ? Thanks.
$Connection=mysqli_connect('localhost','root','','databasename');
$Query="INSERT INTO musteri_ekle(tarih,musteri_ismi,urun_id)
VALUES('$Now','$Musteri_ismi',(SELECT urun_id from urun_ekle WHERE urun_ismi='$Urun_ismi'))";
$Execute=mysqli_query($Connection,$Query);
if($Execute){
$_SESSION["SuccessMessage"]= "Müşteri Eklendi.";
redirect_to("musteri_ekle.php");
} else {
$_SESSION["ErrorMessage"]= $Urun_ismi." -- ".$Musteri_ismi;
redirect_to("musteri_ekle.php");
}
}