我需要能够将PHP Superglobals中包含的数据插入到MySQL数据库表中,从HTML表单接收的一些值将包含不同格式的值,例如“YYYY-MM-DD”,“HH:MM” :SS“以及标准整数。
我认为我的MySQL语法不正确,虽然我在MySQL INSERT
语句中包含了8列我故意遗漏剩余的值,因为我无法弄清楚我的问题在哪里,脚本运行没有错误,但似乎没有数据提交到表中?
这是代码: -
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Post Results</title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
</head>
<body>
<?php
$RunnerID = $_POST['RunnerID'];
$EventID = $_POST['EventID'];
$Date = $_POST['Date'];
$FinishTime = $_POST['FinishTime'];
$Position = $_POST['Position'];
$CategoryID = $_POST['CategoryID'];
$AgeGrade = $_POST['AgeGrade'];
$PB = $_POST['PB'];
echo '<table border=1><tr><th>RunnerID</th><th>EventID</th><th>Date</th><th>FinishTime</th><th>Position</th><th>CategoryID</th><th>AgeGrade</th><th>PB</th></tr>';
{
echo ("Success! Your data has be accepted!");
echo '<tr><td>';
echo htmlspecialchars(print_r($RunnerID, true));
echo '</td><td>';
echo htmlspecialchars(print_r($EventID, true));
echo '</td><td>';
echo htmlspecialchars(print_r($Date, true));
echo '</td><td>';
echo htmlspecialchars(print_r($FinishTime, true));
echo '</td><td>';
echo htmlspecialchars(print_r($Position, true));
echo '</td><td>';
echo htmlspecialchars(print_r($CategoryID, true));
echo '</td><td>';
echo htmlspecialchars(print_r($AgeGrade, true));
echo '</td><td>';
echo htmlspecialchars(print_r($PB, true));
echo '</td></tr>';
}
echo '</table>';
// Database variables
$server = "STRIPPED";
$username = "STRIPPED";
$pwd = "STRIPPED";
// Create the MySQL database connection
$connection = mysql_connect($server, $username, $pwd);
// Check connection is successful
if (!$connection) {
die("Connection failed: " . mysql_connect_error());
}
echo "Connected successfully";
// Select appropriate MySQL database
$database = "STRIPPED";
mysql_select_db($database);
$query = "SELECT * FROM Results";
$result = mysql_query($query);
if(!$result) die("Query Failed.");
$queryStart = "INSERT INTO Results (RunnerID, EventID, Date, FinishTime, Position, CategoryID, AgeGrade, PB) values ("; $queryEnd = ")"; $myQuery = $queryStart . "'$_POST[RunnerID]', '$_POST[EventID]', '$_POST[Date]' '$_POST[FinishTime]', '$_POST[Position]', '$_POST[CategoryID]', '$_POST[AgeGrade]', '$_POST[Values]'" . $queryEnd; mysql_query( $myQuery, $connection);
echo mysql_error($connection);
?>
</body>
</html>