php在清理输入时出错 [英] php giving an error when sanitizing input
本文介绍了php在清理输入时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我插入时,魔术引号有效,但是当我尝试更新一行时,它会出错:
你的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在Road 12,St Julian \',UK''',lat ='''35 .911179'',lng ='''14 .487689'附近使用正确的语法。 ',ca''在第1行
有任何想法吗?
<?php
function check_input($ value){
// Stripslashes
if (get_magic_quotes_gpc( ))
{
$ value = stripslashes($ value);
}
// 引用,如果不是数字
if (!is_numeric($ value))
{
$ value = '。 mysql_real_escape_string($ value)。 ';
}
返回 $ value ;
}
// 获取数据库凭据
require ' config.php';
$ link = mysql_connect($ dbhost,$ dbusername,$ dbpass);
if (!$ link){
die(' 无法连接:' .mysql_error());
}
mysql_select_db($ dbname)或 die(' 无法选择数据库');
$ id = $ _GET [' ID 跨度>];
$ riskCategory = $ _GET [' riskCategory 跨度>];
$ EventAccidentSubject = $ _GET [' EventAccidentSubject 跨度>];
$ description = $ _GET [' description 跨度>];
$ peopleInvolved = $ _GET [' peopleInvolved 跨度>];
$ hazard = $ _GET [' hazard 跨度>];
// $ address = $ _GET ['address'];
< span class =code-sdkkeyword> $ address = check_input($ _ GET [' address'跨度>]);
$ lat = $ _GET [' lat 跨度>];
$ lng = $ _GET [' lng 跨度>];
$ caseStatus = $ _GET [' caseStatus 跨度>];
$ query = 更新dataentry。
SET riskCategory ='。$ riskCategory。 ',。
EventAccidentSubject ='。$ EventAccidentSubject。 ',。
description ='。$ description。 ',。
peopleInvolved ='。$ peopleInvolved。 ',。
hazard ='。$ hazard。 ',。
address ='。$ address。 ',。
lat ='。$ lat。 ',。
lng ='。$ lng。 ',。
caseStatus ='。$ caseStatus。 '。
WHERE id ='。$ id。 ';
// 运行查询
$ result = mysql_query($ query)或 die(mysql_error());
// 链接变量等于引用页面
$ link = $ _SERVER [' HTTP_REFERER'];
// 直接向浏览器发送标题,告知用户将用户重定向到引用页面
header( 位置:$ link);
?>
解决方案
value){
// Stripslashes
if (get_magic_quotes_gpc())
{
value = stripslashes(
值);
}
// 引用,如果不是数字
if (!is_numeric(
When I do an insert the magic quotes work, but when I try to update a row it gives error:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''Road 12, St Julian\''s, UK'''', lat = ''35.911179'', lng = ''14.487689'', ca'' at line 1
Any ideas please?
<?php
function check_input($value){
// Stripslashes
if (get_magic_quotes_gpc())
{
$value = stripslashes($value);
}
// Quote if not a number
if (!is_numeric($value))
{
$value = "'" . mysql_real_escape_string($value) . "'";
}
return $value;
}
//Get database credentials
require 'config.php';
$link = mysql_connect($dbhost, $dbusername,$dbpass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($dbname) or die('Cannot select database');
$id = $_GET['id'];
$riskCategory = $_GET['riskCategory'];
$EventAccidentSubject = $_GET['EventAccidentSubject'];
$description = $_GET['description'];
$peopleInvolved = $_GET['peopleInvolved'];
$hazards = $_GET['hazards'];
//$address = $_GET['address'];
$address = check_input($_GET['address']);
$lat = $_GET['lat'];
$lng = $_GET['lng'];
$caseStatus = $_GET['caseStatus'];
$query = "UPDATE dataentry" .
" SET riskCategory = '".$riskCategory."'," .
" EventAccidentSubject = '".$EventAccidentSubject."'," .
" description = '".$description."'," .
" peopleInvolved = '".$peopleInvolved."'," .
" hazards = '".$hazards."'," .
" address = '".$address."',".
" lat = '".$lat."'," .
" lng = '".$lng."'," .
" caseStatus = '".$caseStatus."'" .
" WHERE id = '".$id."'";
//Run the query
$result = mysql_query($query) or die(mysql_error());
//link variable is equal to the referring page
$link = $_SERVER['HTTP_REFERER'];
//sends a header directly to the browser telling it to redirect the user to the referring page
header("Location: $link");
?>
解决方案
value){ // Stripslashes if (get_magic_quotes_gpc()) {
value = stripslashes(
value); } // Quote if not a number if (!is_numeric(
这篇关于php在清理输入时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文