gpt4 book ai didi

php - HTTP Post 不向数据库发送数据?

转载 作者:可可西里 更新时间:2023-11-01 16:34:37 26 4
gpt4 key购买 nike

我正在尝试从 android 应用程序将一些数据发送到 mysql 数据库,数据是字符串形式(它是用户完成的测验的结果),我不确定问题是什么。

这是我的 HTTP Post android 代码:

// http post
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost("http://ast.ncl-coll.ac.uk/~cmaughan/firesafety/app_results.php");

try {
//Link to quiz string results
List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("StaffID","StaffID"));
nameValuePairs.add(new BasicNameValuePair("Forename","Forename"));
nameValuePairs.add(new BasicNameValuePair("Surname", "Surname"));
nameValuePairs.add(new BasicNameValuePair("Score", "Score"));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

HttpResponse response = httpclient.execute(httppost);
HttpEntity entity = response.getEntity();
InputStream is = entity.getContent();
} catch (Exception e) {
Log.e("log_tag", "Error in http connection " + e.toString());
Toast.makeText(getApplicationContext(),

这是我的 php:

<?php
include('./inc/connection.inc.php');
connect();
//retrieve the data
$StaffID = $_POST['StaffID'];
$Forename = $_POST['Forename'];
$Surname = $_POST['Surname'];
$Score = $_POST['Score'];

//Insert into the database
$sql = "INSERT INTO tblQuiz (staffid, forename, surname, score) VALUES ('$StaffID', '$Forename', '$Surname', '$Score')";

$result = mysql_query($sql) or die("Could not run query");



// Close connection to the database

mysql_close();


// Echo success
echo "Upload Successful";


?>

任何帮助将不胜感激,我认为数组是错误的,因为我正在尝试使用 HTTP Post 方法发送字符串

注意事项:*测验的结果将进入 DDMS 中的 mysqllite 数据库,我只想将这些结果上传到 php/mysql 数据库。*

最佳答案

试试这个:

$sql = "INSERT INTO tblQuiz (staffid, forename, surname, score) VALUES ('".$_POST['StaffID']."',     '".$_POST['Forename']."', '".$_POST['Surname']."', '".$_POST['Score']."')";

关于php - HTTP Post 不向数据库发送数据?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10617616/

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