php在清理输入时出错 [英] php giving an error when sanitizing input

查看:74
本文介绍了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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆