我无法插入到表中,因为查询具有未定义的变量startDate和endDate,我用ajax将其转移到php,但我不知道为什么它会在php查询中写入未定义的变量
<!-- language: lang-php -->
//file insertDatenbank.php
//PHP PART
<?php
$localhost = "localhost";
$username = "root";
$password = "";
$db = "gpsauge_projektarbeit2";
$link = mysqli_connect($localhost, $username, $password, $db);
if(!$link){
echo "Keine Verbindung";
}
if(!empty($_POST["startDatum"]) && !empty($_POST["endDatum"]))
{
$startDatum = mysqli_real_escape_string($link, $_POST["startDatum"]);
$endDatum = mysqli_real_escape_string($link, $_POST["endDatum"]);
} else{
echo "Probleme bei Variablen Initialisierung";
}
$query = "insert into urlaubsantrag (start_datum, end_datum) values ('$startDatum', '$endDatum');";
var_dump($query);
$sql = mysqli_query($link, $query);
if($sql == true){
echo "erfolgreich";
} else{
echo "probleme ende";
}
<!-- language: lang-php -->
//file beantragen.php
<!--HTML-STARTDATUM---------------------------------------------------------->
<div class="container">
<div class="row">
<h2>Startdatum</h2>
</div>
<div class="row">
<div class='col-sm-6'>
<div class="form-group">
<div class='input-group date' id='datepicker'><!--id="startDatum" = ENDATE"-->
<input type='text' id="startDatum" class="form-control" />
<span class="input-group-addon">BLABLA
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
</div>
</form>
</div>
</div>
</div>
<!--HTML-ENDDATUM----------------------------------------------------------->
<p id="data">Hier muss Data stehen</p>
<div class="container">
<div class="row">
<h2>Enddatum</h2>
</div>
<div class="row">
<div class='col-sm-6'>
<form>
<div class="form-group">
<div class='input-group date' id='datepicker2'> <!--id="endDatum" = ENDATE"-->
<input type='text' id="endDatum" class="form-control"/>
<span class="input-group-addon">BLABLA
<span class="glyphicon glyphicon-calendar"></span>
</span>
</div>
<br><input id="button" type="button" value="Bestätigen">
</div>
</form>
</div>
</div>
</div>
<!--AJAX PART----------------------------------------------------------------->
$(document).ready(function(){
$('#button').click(function(){
var startDatum = $('#startDatum').val();
var endDatum = $('#endDatum').val();
$.ajax({
type: "post",
url: "insertDatenbank.php",
data: {
startDatum: startDatum,
endDatum: endDatum
},
success: function (data) {
$('#data').html(data);
}
});
});
});
错误消息:变量初始化问题注意: 未定义的变量:中的startDatum /opt/lampp/htdocs/dashboard/USFACHINFORMATIKERIBBUNDIHK/PRAKTIKUM/TESTSUMGEBUNG/CALENDAR_VERSUCH_3/insertDatenbank.php 在第22行
注意:未定义变量:endDatum在 /opt/lampp/htdocs/dashboard/USFACHINFORMATIKERIBBUNDIHK/PRAKTIKUM/TESTSUMGEBUNG/CALENDAR_VERSUCH_3/insertDatenbank.php 在第22行string(67)“上插入urlaubsantrag(start_datum, end_datum)值('','');“ erfolgreich