gpt4 book ai didi

java - 如何使用 $_GET 将 Textview 值放入 URL 中以从 PHP 接收

转载 作者:行者123 更新时间:2023-12-02 11:41:08 24 4
gpt4 key购买 nike

请原谅我问这个问题,但我是 Android 开发新手。因此,我尝试将 TextView 值放入我的 URL 中,在我的 webservice(PHP) 中,我有 $_GET 来测试我的查询并仅显示字段名称“WHERE CODE_ID =”所需的匹配值.$样本。”

CameraTestActivity.class

if (!scanText.getText().toString().matches("")){

//set the scan text from bar code label
scanText.setText(sym.getData());

//if Text scan the Content Automatic go to another Activity and pass the scan text from Main Activity

Intent i = new Intent(CameraTestActivity.this, MainActivity2.class);
i.putExtra("code_id", content);
startActivity(i);
finish();
}

MainActivity2.class

//trying to put the TextValue of scanText into tvView
tvView = (TextView)findViewById(R.id.textView9);
tvView.setText(getIntent().getExtras().getString("code_id"));

String ServerURL = ("https://asec-domain.000webhostapp.com/select.php?code_id=" + tvView);

getAll.php

if (isset($_GET['code_id'])) 
{
$id = $_GET['code_id'];
}

// Create connection

$conn = new mysqli($HOST='localhost', $USER='id4400742_asec_domain', $PASS='asec@l0cal', $DB='id4400742_tbl_data');

if ($conn->connect_error) {

die("Connection failed: " . $conn->connect_error);
}

$sql = "SELECT * FROM tbl_ComputerDetails WHERE CODE_ID= id ";

$result = $conn->query($sql);

if ($result->num_rows >0) {

while($row[] = $result->fetch_assoc()) {

$tem = $row;

$json = json_encode($tem);

}

echo $json;

}

else
{

echo "No Results Found.";
}
$conn->close();
?>

最佳答案

你必须这样做

如果 id 是数字:

$sql = "SELECT * FROM tbl_ComputerDetails WHERE CODE_ID = ".$id; 

如果 id 是字符串

$sql = "SELECT * FROM tbl_ComputerDetails WHERE CODE_ID = '".$id."'";

否则 id 只是字符串“id”,而不是从 GET 检索到的数字。顺便说一句,由于 SQL 注入(inject),这不是一个好的做法

发布内容时始终隐藏您的密码和用户名

所以在 Android 中你会错过这个:

//trying to put the TextValue of scanText into tvView
tvView = (TextView)findViewById(R.id.textView9);
tvView.setText(getIntent().getExtras().getString("code_id"));

//You are not getting the string you are just passing the textview
String result = getIntent().getExtras().getString("code_id");

String ServerURL = ("https://asec-domain.000webhostapp.com/select.php?code_id=" + result);

关于java - 如何使用 $_GET 将 Textview 值放入 URL 中以从 PHP 接收,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48537145/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com