当我点击索引表单上的提交时,它应该提交到数据库。这不会发生。单击提交后,我被重定向到一个新的URL,其地址与我的php页面相同。 这是我的索引代码和我的PHP代码。它们位于aptana的单独页面中。
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#Datepicker" ).datepicker();
});
function submitfunction(){
event.preventDefault();
var Operator = $( "#Operator" ).val();
var Datepicker = $( "#Datepicker" ).val();
var Start_Cycle_Time = $( "#Start_Cycle_Time" ).val();
var Start_Cycle_TotalizerValue = $( "#Start_Cycle_TotalizerValue" ).val();
var Receiving_Tank = $( "#Receiving_Tank" ).val();
var End_Cycle_Time = $( "#End_Cycle_Time" ).val();
var End_Cycle_TotalizerValue = $( "#End_Cycle_TotalizerValue" ).val();
var DE (PreCoat) = $( "#DE (PreCoat)" ).val();
var _600R (RemovesAcid) = $( "#_600R (RemovesAcid)" ).val();
var R60 (RemovesWaxes) = $( "#R60 (RemovesWaxes)" ).val();
var D60 (RemovesMoistureAndGlycerin) = $("#D60 (RemovesMoistureAndGlycerin)").val();
var Filter_Sock = $( "#Filter_Sock" ).val();
alert("submit called");//this is an alert that pops up when the submit button is selected
alert(Operator);//this is an alert that pops up after a start date is selected and shows after the submit button
alert(Datedatepicker);//an alert for the end date that shows after the submit button
alert(Start_Cycle_Time);//alert for project name
alert(Start_Cycle_TotalizerValue);//alert for milestone description
alert(Receiving_Tank);//alert for entered by.
alert(End_Cycle_Time);
alert(End_Cycle_TotalizerValue);
alert(DE (PreCoat));
alert(_600R (RemovesAcid));
alert(R60 (RemovesWaxes));
alert( D60 (RemovesMoistureAndGlycerin));
alert(Filter_Sock);
$.getJSON('bleaching_report.php',{
Operator: Operator,
Datedatepicker: Datepicker,
Start_Cycle_Time: Start_Cycle_Time,
Start_Cycle_TotalizerValue: Start_Cycle_TotalizerValue,
Receiving_Tank: Receiving_Tank,
End_Cycle_Time: End_Cycle_Time,
End_Cycle_TotalizerValue: End_Cycle_TotalizerValue,
DE (PreCoat): DE (PreCoat),
_600R (RemovesAcid): _600R (RemovesAcid),
R60 (RemovesWaxes): R60 (RemovesWaxes),
D60 (RemovesMoistureAndGlycerin),
Filter_Sock: Filter_Sock,
},
function(res,status){
alert(status);
alert(res.message);
});
}
</script>
</head>
<body>
<h1><bold><center>Bleaching Report</center></bold></h1>
<form action="bleaching_report.php" method="get">
Operator: <input type="text" id="Operator">
Date: <input tupe="text" id="Datepicker"> <br><br>
Start_Cylce_Time: <input tupe= "text" id="Start_Cycle_Time"> <br><br>
Start_Cycle_TotalizerValue: <input type= "text" id="Start_Cycle_TotalizerValue"> <br><br>
Receiving_Tank: <input tupe= "text" id="Receiving_Tank"> <br><br>
End_Cycle_Time: <input tupe= "text" id="End_Cycle_Time"> <br><br>
End_Cycle_TotalizerValue: <input tupe= "text" id="End_Cycle_TotalizerValue"> <br><br>
DE (PreCoat): <input tupe= "text" id="DE (PreCoat)"> <br><br>
_600R (RemovesAcid): <input tupe= "text" id="_600R (RemovesAcid)"> <br><br>
R60 (RemovesWaes): <input tupe= "text" id="R60 (RemovesWaxes)"> <br><br>
D60 (RemovesMoistureAndGlycerin): <input tupe= "text" id="D60 (RemovesMoistureAndGlycerin)"> <br><br>
Filter_Sock: <input tupe= "text" id="Filter_Sock"> <br><br>
<input type="submit" value="Submit Form" onclick="submitfunction()">
</form>
</body>
</html>
<?php
$Operator = $_GET['Operator'];
$Date = $_GET['Date'];
$Start_Cycle_Time = $_GET['Start_Cycle_Time'];
$Start_Cycle_TotalizerValue = $_GET['Start_Cycle_TotalizerValue'];
$Receiving_Tank = $_GET['Receiving_Tank'];
$End_Cylce_Time = $_GET['End_Cycle_Time'];
$End_Cylce_TotalizerValue = $_GET['End_Cylce_TotalizerValue'];
$DE (PreCoat) = $_GET['DE (PreCoat)'];
$_600R (RemovesAcid) = $_GET['_600R (RemovesAcid)'];
$R60 (RemovesWaxes) = $_GET['R60 (RemovesWaxes)'];
$D60 (RemovesMoistureAndGlycerin) = $_GET['D60 (RemovesMoistureAndGlycerin)'];
$Filter_Socks = $_GET['Filter_Socks'];
$con=mysqli_connect("localhost","root","MySQLr00t","WRE_Plym");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_query($con,"INSERT INTO bleaching_report (Operator, Date, Start_Cycle_Time, Start_Cycle_TotalizerValue, Receiving_Tank,
End_Cycle_Time, End_Cylce_TotalizerValue, DE (PreCoat), _600R (RemovesAcid), R60 (RemovesWaxes), D60 (RemovesMoistureAndGlycerin), Filter_Socks)
VALUES ( '$Operator', '$Date', '$Start_Cycle_Time', '$Start_Cycle_TotalizerValue', '$Receiving_Tank', '$End_Cylce_Time', '$End_Cylce_TotalizerValue', '$DE (PreCoat)',
'$_600R (RemovesAcid)', '$R60 (RemovesWaxes)', '$D60 (RemovesMoistureAndGlycerin)', '$Filter_Socks')");
mysqli_select_db($con, "WRE_Plym") or die(mysqli_error());
$sql = "SELECT * FROM `bleaching_report` ";
$result = mysqli_query($sql);
while($row = mysqli_fetch_array($result)){
echo $row['Operator']. "<br>";
echo $row['Date']. "<br>";
echo $row['Start_Cycle_Time']. "<br>";
echo $row['Start_Cycle_TotalizerValue']. "<br>";
echo $row['Receiving_Tank']. "<br>";
echo $row['End_Cycle_Time']. "<br>";
echo $row['End_Cylce_TotalizerValue']. "<br>";
echo $row['DE (PreCoat)']. "<br>";
echo $row['_600R (RemovesAcid)']. "<br>";
echo $row['R60 (RemovesWaxes)']. "<br>";
echo $row['D60 (RemovesMoistureAndGlycerin)']. "<br>";
echo $row['Filter_Socks']. "<br>";
}
mysqli_close($con);
?>
答案 0 :(得分:0)
您有几个错误。首先,您没有在文本框中使用name
属性。如果没有name
您的文本框,您将无法从查询字符串中下拉项目。
Operator: <input type="text" name="Operator" id="Operator"> // Add "name"
你也错误地在各个地方拼写“类型”:
更新:我对您的代码进行了一些更正。看起来你还没有试过运行它 - 或者我怀疑你自己已经发现了很多这些语法错误。在请求更多帮助之前请先测试一下!
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>jQuery UI Datepicker - Default functionality</title>
<link rel="stylesheet" href="http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css">
<link rel="stylesheet" href="/resources/demos/style.css">
<script src="http://code.jquery.com/jquery-1.9.1.js"></script>
<script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>
<script>
$(function() {
$( "#Datepicker" ).datepicker();
});
function submitfunction(){
event.preventDefault();
var Operator = $( "#Operator" ).val();
var Datepicker = $( "#Datepicker" ).val();
var Start_Cycle_Time = $( "#Start_Cycle_Time" ).val();
var Start_Cycle_TotalizerValue = $( "#Start_Cycle_TotalizerValue" ).val();
var Receiving_Tank = $( "#Receiving_Tank" ).val();
var End_Cycle_Time = $( "#End_Cycle_Time" ).val();
var End_Cycle_TotalizerValue = $( "#End_Cycle_TotalizerValue" ).val();
var DE (PreCoat) = $( "#DE (PreCoat)" ).val();
var _600R (RemovesAcid) = $( "#_600R (RemovesAcid)" ).val();
var R60 (RemovesWaxes) = $( "#R60 (RemovesWaxes)" ).val();
var D60 (RemovesMoistureAndGlycerin) = $("#D60 (RemovesMoistureAndGlycerin)").val();
var Filter_Sock = $( "#Filter_Sock" ).val();
alert("submit called");//this is an alert that pops up when the submit button is selected
alert(Operator);//this is an alert that pops up after a start date is selected and shows after the submit button
alert(Datedatepicker);//an alert for the end date that shows after the submit button
alert(Start_Cycle_Time);//alert for project name
alert(Start_Cycle_TotalizerValue);//alert for milestone description
alert(Receiving_Tank);//alert for entered by.
alert(End_Cycle_Time);
alert(End_Cycle_TotalizerValue);
alert(DE (PreCoat));
alert(_600R (RemovesAcid));
alert(R60 (RemovesWaxes));
alert( D60 (RemovesMoistureAndGlycerin));
alert(Filter_Sock);
$.getJSON('bleaching_report.php',{
Operator: Operator,
Datedatepicker: Datepicker,
Start_Cycle_Time: Start_Cycle_Time,
Start_Cycle_TotalizerValue: Start_Cycle_TotalizerValue,
Receiving_Tank: Receiving_Tank,
End_Cycle_Time: End_Cycle_Time,
End_Cycle_TotalizerValue: End_Cycle_TotalizerValue,
DE (PreCoat): DE (PreCoat),
_600R (RemovesAcid): _600R (RemovesAcid),
R60 (RemovesWaxes): R60 (RemovesWaxes),
D60 (RemovesMoistureAndGlycerin),
Filter_Sock: Filter_Sock,
},
function(res,status){
alert(status);
alert(res.message);
});
}
</script>
</head>
<body>
<h1><bold><center>Bleaching Report</center></bold></h1>
#
# EDIT: Added "name" property to each of your input boxes.
#
<form action="bleaching_report.php" method="get">
Operator: <input type="text" name="Operator" id="Operator">
Date: <input type="text" name="Date" id="Datepicker"> <br><br>
Start_Cylce_Time: <input type="text" name="Start_Cycle_Time" id="Start_Cycle_Time"> <br><br>
Start_Cycle_TotalizerValue: <input type="text" name="Start_Cycle_TotalizerValue" id="Start_Cycle_TotalizerValue"> <br><br>
Receiving_Tank: <input type="text" name="Receiving_Tank" id="Receiving_Tank"> <br><br>
End_Cycle_Time: <input type= "text" name="End_Cycle_Time" id="End_Cycle_Time"> <br><br>
End_Cycle_TotalizerValue: <input type="text" name="End_Cycle_Totalizer_Value" id="End_Cycle_TotalizerValue"> <br><br>
DE (PreCoat): <input type="text" name="DE_PRECOAT" id="DE (PreCoat)"> <br><br>
_600R (RemovesAcid): <input type="text" name="600R" id="_600R (RemovesAcid)"> <br><br>
R60 (RemovesWaes): <input type="text" name="R60" id="R60 (RemovesWaxes)"> <br><br>
D60 (RemovesMoistureAndGlycerin): <input type="text" name="D60" id="D60 (RemovesMoistureAndGlycerin)"> <br><br>
Filter_Sock: <input type= "text" name="Filter_Socks" id="Filter_Sock"> <br><br>
<input type="submit" value="Submit Form" onclick="submitfunction()">
</form>
</body>
</html>
<?php
//
// If we get the Operator variable, we can continue.
//
#
# EDIT: Added check for "OPERATOR". The query won't run unless it's in the query string.
#
if ($_GET['Operator'])
{
#
# EDIT: Updated your GET's to match the names of your input boxes. Note that things like $_GET['R60 (RemovesWaxes)']
# are not reliable ways of capturing data from query strings.
$Operator = $_GET['Operator'];
$Date = $_GET['Date'];
$Start_Cycle_Time = $_GET['Start_Cycle_Time'];
$Start_Cycle_TotalizerValue = $_GET['Start_Cycle_TotalizerValue'];
$Receiving_Tank = $_GET['Receiving_Tank'];
$End_Cylce_Time = $_GET['End_Cycle_Time'];
$End_Cylce_TotalizerValue = $_GET['End_Cycle_TotalizerValue'];
$DE_PRECOAT = $_GET['DE_PRECOAT'];
$_600R (RemovesAcid) = $_GET['600R'];
$R60 (RemovesWaxes) = $_GET['R60'];
$D60 (RemovesMoistureAndGlycerin) = $_GET['D60'];
$Filter_Socks = $_GET['Filter_Socks'];
$con=mysqli_connect("localhost","root","MySQLr00t","WRE_Plym");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
#
# EDIT: Added "if/else" to your MySQL failure block. If your connection fails, why try to evaluate a MySQL query?
#
else
{
#
# TODO - You need to update your $row's to match what's actually in the database.
#
mysqli_query($con,"INSERT INTO bleaching_report (Operator, Date, Start_Cycle_Time, Start_Cycle_TotalizerValue, Receiving_Tank,
End_Cycle_Time, End_Cylce_TotalizerValue, DE (PreCoat), _600R (RemovesAcid), R60 (RemovesWaxes), D60 (RemovesMoistureAndGlycerin), Filter_Socks)
VALUES ( '$Operator', '$Date', '$Start_Cycle_Time', '$Start_Cycle_TotalizerValue', '$Receiving_Tank', '$End_Cylce_Time', '$End_Cylce_TotalizerValue', '$DE (PreCoat)',
'$_600R (RemovesAcid)', '$R60 (RemovesWaxes)', '$D60 (RemovesMoistureAndGlycerin)', '$Filter_Socks')");
mysqli_select_db($con, "WRE_Plym") or die(mysqli_error());
$sql = "SELECT * FROM `bleaching_report` ";
$result = mysqli_query($sql);
while($row = mysqli_fetch_array($result)){
echo $row['Operator']. "<br>";
echo $row['Date']. "<br>";
echo $row['Start_Cycle_Time']. "<br>";
echo $row['Start_Cycle_TotalizerValue']. "<br>";
echo $row['Receiving_Tank']. "<br>";
echo $row['End_Cycle_Time']. "<br>";
echo $row['End_Cylce_TotalizerValue']. "<br>";
echo $row['DE (PreCoat)']. "<br>";
echo $row['_600R (RemovesAcid)']. "<br>";
echo $row['R60 (RemovesWaxes)']. "<br>";
echo $row['D60 (RemovesMoistureAndGlycerin)']. "<br>"; // Are you sure this is how it's stored in your DB?
echo $row['Filter_Socks']. "<br>";
}
mysqli_close($con);
}
}
?>