我对数据库中的元素有疑问。 我有3张桌子:
prenotazione(id,nome_rich,cogn_rich,email_rich,oggetto_rich,data_richiesta,orario_richiesta)
interni(nome_int,cogn_int,email_int,id)
esterni(nome_est,cogn_est,email_est,id)
在我的索引文件中,用户可以添加多个选择字段(“ interno”和“ esterno”)。
我的问题是我想将“ richiedente” ID连接到所有“ interno”和“ esterno” ID,以便当我打印“ richiedente”的某个ID时,它还会打印所有已连接“ interno”和“ esterno”的ID。
目前,我已在序列号中设置了“ interno”和“ esterno”的ID(我使用Postgres),因此,当用户提交表单时,例如,“ interno”和“ esterno”具有3个不同的ID
我粘贴我的代码: index.php
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<title>Prenotazione Videoconferenza</title>
<!-- INIZIO SCRIPT AGGIUNTA DINAMICA -->
<script>
$(document).ready(function() {
$("#add1").click(function(e){
var val1 =$("#n1").val();
for(var i=0;i<val1;i++){
$("#start").append($("#first").clone());
}
});
});
$(document).ready(function() {
$("#add2").click(function(){
var val2 =$("#n2").val();
for(var i=0;i<val2;i++){
$("#start2").append($("#first2").clone());
}
});
});
</script>
<!-- FINE SCRIPT AGGIUNTA DINAMICA -->
<!-- INIZIO SCRIPT CALENDARIO -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="https://code.jquery.com/jquery-1.12.4.js"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/timepicker/1.3.5/jquery.timepicker.min.js"></script>
<script>
$(function() {
$("#datepicker").datepicker();
$('.timepicker').timepicker({
timeFormat: 'h:mm p',
interval: 60,
minTime: '8',
maxTime: '08:00pm',
defaultTime: '11',
startTime: '08:00',
dynamic: false,
dropdown: true,
scrollbar: true
});
});
</script>
<!-- FINE SCRIPT CALENDARIO -->
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<!-- NAV -->
<div class="nav">
<h1>Inserire i dati richiesti:</h1><br><br>
</div>
<!-- FORM GENERALE SINISTRA-->
<div class="form">
<div class="left">
<form method="post" action="input.php">
<!-- FORM RICHIEDENTE -->
<div class="form_1">
<b> Richiedente Conferenza:</b>
<br>
<br>
Nome:<input type="text" name="name" size="20"><br>
Cognome:<input type="text" name="surname" size="20"><br>
Email: <input type="email" name="email" size="20"><br>
Oggetto Conferenza:<br><textarea name="testo" rows="5" cols="40" placeholder="Specificare oggetto Videoconferenza"></textarea><br>
</div>
<!-- FINE FORM RICHIEDENTE -->
<br>
<!-- FORM INTERNO -->
<div class="form_2">
<b>Partecipanti Interni</b>
<br>
<br>
<b> Numero partecipanti interni:</b>
<input type="text" id="n1" value="1"><br>
<button><a href="#" id="add1">Aggiungi partecipante</a></button><br>
<br>
<div id="start">
<div id="first">
Nome:<input type="text" name="iname[]" size="20"><br>
Cognome: <input type="text" name="isurname[]" size="20"><br>
Email: <input type="email" name="iemail[]" size="20"><br>
<br>
</div>
</div>
<br>
</div>
<!-- FINE FORM INTERNO -->
<br>
<!-- FORM ESTERNO -->
<b>Partecipanti Esterni</b>
<br>
<br>
Numero partecipanti Esterni:
<input type="text" id="n2" value="1"><br>
<button><a href="#" id="add2">Aggiungi partecipante</a></button><br>
<div id="start2">
<div id="first2">
Nome:<input type="text" name="ename[]" size="20"><br>
Cognome: <input type="text" name="esurname[]" size="20"><br>
Email: <input type="email" name="eemail[]" size="20"><br>
<br>
</div>
</div>
<!-- FINE FORM ESTERNO -->
<input type="submit" value="Invia" >
</div>
</div>
<!-- INIZIO FORM DI DESTRA -->
<div id="right">
Date:<br>
<input name="datepicker" id="datepicker" type="text"><br> Orario:
<br>
<input name="hour" type="text" class="timepicker"><br>
</div>
<!-- FINE FORM DI DESTRA -->
</form>
<!-- FINE FORM GENERALE SINISTRA -->
</body>
</html>
input.php
<?php
$conn = @pg_connect("dbname=postgres user=postgres password=123456789");
if(!$conn) {
die('Connessione fallita !<br />');
} else {
echo 'Richiesta Effettuata !<br />';
}
// Richiedente
$name = $_POST['name'];
$surname = $_POST['surname'];
$email = $_POST['email'];
$testo = $_POST['testo'];
$str_data = $_POST['datepicker'];
$str_hour = $_POST['hour'];
//inserting data order
$query1 = "INSERT INTO prenotazione (id,nome_rich, cogn_rich, email_rich,oggetto_rich,data_richiesta,orario_richiesta) VALUES (1,'$name','$surname', '$email','$testo','$str_data', '$str_hour')";
//execute the query here
$result = pg_query($conn, $query1 ); //if you are using pg_query and $conn is the connection resource
// Interni
$query = "";
if( !empty( $_POST['iname'] ) ) {
foreach( $_POST['iname'] as $key => $iname ) {
$isurname = empty( $_POST[$key]['isurname'] ) ? NULL : $_POST[$key]['isurname'];
$iemail = empty( $_POST[$key]['iemail'] ) ? NULL : $_POST[$key]['iemail'];
if ($query != "" ) {
$query .= ",";
}
$query .= " ( '$iname', '$isurname', '$iemail' ) ";
}
}
if( !empty( $query ) ) {
$query2 = "INSERT INTO interni (nome_int, cogn_int, email_int) VALUES ".$query;
$result = pg_query($conn, $query2 ); //if you are using pg_query and $conn is the connection resource
}
// Esterni
$query = "";
if( !empty( $_POST['ename'] ) ) {
foreach( $_POST['ename'] as $key => $ename ) {
$esurname = empty( $_POST[$key]['esurname'] ) ? NULL : $_POST[$key]['esurname'];
$eemail = empty( $_POST[$key]['eemail'] ) ? NULL : $_POST[$key]['eemail'];
if ($query != "" ) {
$query .= ",";
}
$query .= " ( '$ename', '$esurname', '$eemail' ) ";
}
}
if( !empty( $query ) ) {
$query3 = "INSERT INTO esterni (nome_est, cogn_est, email_est) VALUES " . $query;
$result = pg_query($conn, $query3 ); //if you are using pg_query and $conn is the connection resource
}
// Calendario
/*
$str_data = addslashes($_POST['datepicker']);
$str_hour = addslashes($_POST['hour']);
$sql = "INSERT INTO appuntamenti (str_data,hour ) VALUES ('$str_data', '$str_hour')";
*/
?>
我希望我能解释我的问题。谢谢大家的帮助