我已多次使用mysqli_stmt_bind_param函数.但是,如果我将我试图防止SQL注入的变量分开,我会遇到错误.
这是一些代码示例:
function insertRow( $db, $mysqli, $new_table, $Partner, $Merchant, $ips, $score, $category, $overall, $protocol )
{
$statement = $mysqli->prepare("INSERT INTO " .$new_table . " VALUES (?,?,?,?,?,?,?);");
mysqli_stmt_bind_param( $statment, 'sssisss', $Partner, $Merchant, $ips, $score, $category, $overall, $protocol );
$statement->execute();
}
Run Code Online (Sandbox Code Playgroud)
是否有可能以某种方式.$new_table.
用另一个问号语句替换连接,创建另一个绑定参数语句,或添加到现有的语句以防止SQL注入?
像这样或某种形式:
function insertRow( $db, $mysqli, $new_table, $Partner, $Merchant, $ips, $score, $category, $overall, $protocol )
{
$statement = $mysqli->prepare("INSERT INTO (?) VALUES (?,?,?,?,?,?,?);");
mysqli_stmt_bind_param( $statment, 'ssssisss', $new_table, $Partner, $Merchant, $ips, $score, $category, $overall, $protocol );
$statement->execute();
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用JSON来启动对API的POST请求.
我找到了一些示例代码,在我走得太远之前我想让它工作,但我被卡住了......
<html>
<head>
<script type="text/javascript">
function JSONTest()
{
requestNumber = JSONRequest.post(
"https://example.com/api/",
{
apikey: "23462",
method: "example",
ip: "208.74.35.5"
},
function (requestNumber, value, exception) {
if (value) {
processResponse(value);
} else {
processError(exception);
}
}
);
}
</script>
</head>
<body>
<h1>My JSON Web Page</h1>
<button type="button" onclick="JSONTest()">JSON</button>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
这是一个.html文件,我在chrome中运行.单击按钮时没有任何反应......
我想我错过了一段解释JSON响应并可以显示的javascript?否则任何其他建议?
有人可以帮助我更好地理解同源政策.我已经看过几个描述它的网站,但我正在寻找一个更简单的解释,你会如何描述它?
这个链接 似乎是我找到的最好的工作.谁能扩展?有人可以解释为什么这个政策存在?
我试着打电话给我写的方法.它编译除了一行...
public class http extends Activity {
httpMethod(); //will not compile
public void httpMethod(){
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://site/api/");
try {
// Add your data
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2);
// Execute HTTP Post Request
HttpResponse response = httpclient.execute(httppost);
String test = "hello";
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText(test);
} catch (ClientProtocolException e) {
// TODO Auto-generated catch block
} catch (IOException e) {
// TODO Auto-generated catch block
}
}
}
Run Code Online (Sandbox Code Playgroud)
我不是最好的java人,但我认为调用这样的方法会得到回应.然而,"Hello"没有显示......
我该如何正确调用该方法?
我得到了一些我似乎无法解决的错误......这是示例代码,所以我很困惑发生了什么.错误被注释到它们出现的行的一侧.
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLEncoder;
public class Connect {
URL url;
URLConnection urlConnection;
DataOutputStream outStream;
DataInputStream inStream;
// Build request body
String body = "fname=" + URLEncoder.encode("Atli", "UTF-8"); //Syntax error on token ";", { expected after this token
// Create connection
url = new URL("http://192.168.1.68/test/POST/post.php");
urlConnection = url.openConnection();
((HttpURLConnection)urlConnection).setRequestMethod("POST");
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
urlConnection.setRequestProperty("Content-Length", ""+ body.length());
// Create I/O streams
outStream = new DataOutputStream(urlConnection.getOutputStream());
inStream = new DataInputStream(urlConnection.getInputStream());
// Send request
outStream.writeBytes(body);
outStream.flush(); …
Run Code Online (Sandbox Code Playgroud) 我在数据库中有两个大表.它们都包含一个名为"name"的列.我的目标是找到包含一个数据库但不包含另一个数据库的名称的行.
我猜测会有一个连接语句和一个地方,但我无法弄清楚如何使用这两个串联来创建一个成功的查询.
建议?