php where 后 函数,PHP – GetSQLValueString函数

标签:php

我看到一个函数Ge​​tSQLValueString,我不知道它处理的是什么,有人可以给我一些想法吗?

谢谢

function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")

{

$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

switch ($theType) {

case "text":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "long":

case "int":

$theValue = ($theValue != "") ? intval($theValue) : "NULL";

break;

case "double":

$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";

break;

case "date":

$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";

break;

case "defined":

$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;

break;

}

return $theValue;

}

这里使用的函数:

if (isset($_POST['username'])) {

$loginUsername=$_POST['username'];

$password=$_POST['password'];

$MM_fldUserAuthorization = "";

$MM_redirectLoginSuccess = "main.php";

$MM_redirectLoginFailed = "login_form.php";

$MM_redirecttoReferrer = false;

mysql_select_db($database_connection1, $connection1);

$LoginRS__query=sprintf("SELECT username, password FROM member WHERE username=%s AND password=%s",

GetSQLValueString($loginUsername, "text"), GetSQLValueString($password, "text"));

...

解决方法:

您的函数使用MySQL的内置字符串转义函数转义字符串,然后如果它是非数字值,则用单引号括起来.编写此函数是为了将可变数据插入SQL查询中.

$sql = "SELECT * FROM users WHERE username = " . GetSQLValueString($_GET['username'], 'text');

$result = mysql_query($sql);

标签:php

来源: https://codeday.me/bug/20190526/1157373.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值