您没有验证任何传递的数据。此外,我建议将 MySQLi 用于准备好的语句,以使事情更安全一些。
// create a new MySQLi object
$mysqli = new mysqli('host', 'user', 'password', 'database');
// create var for each POST array item you need
$slots_sold = $_POST['slots_sold'];
$total_figure = $_POST['total_figure'];
$apps_sat = $_POST['apps_sat'];
//check to make sure each field is set
if(isset($slots_sold) && isset($total_figure) && isset($apps_sat))
{
// prepare mysqli statement for your data
if($stmt->prepare("UPDATE stats SET `slots_sold` = ?, `total_figure` = ?, `apps_sat` = ?"))
{
// bind each variable to query, respectively (? is place holder for var)
// s = string ('sss' means three strings). i = integer if needed
$stmt->bind_param('sss', $slots_sold, $total_figure, $apps_sat);
$stmt->execute(); // execute your query
}
else
{
$stmt->error; // there was an error with the query, show the error
}
}
else
{
echo 'You did not fill out all of the fields.';
}
$stmt->close; // close mysqli connection
希望这会对您有所帮助。根据您传递的数据,我会使用 preg_match 来检查每个数据。这里有一些非常简单的正则表达式可以帮助您入门:
/[a-zA-Z ]+/ (Any letter, lowercase or uppercase including spaces atleast once)
/[a-zA-Z]+/ (Same as above, without spaces atleast once)
/[a-zA-Z0-9]+/ (Any letter, lowercase or uppercase including numbers atleast once)
/[0-9]+/ (Any number atleast once)
preg_match('/[a-zA-Z]+/', $str, $matches); // you can throw this in a for loop to check each var if they all require the same pattern