-1

我正在使用 get 方法从 mysql 数据库中获取值我从 url 传递survey_id 和 question_id

如下 http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1,question_id=1

但它给出了错误

下面给出了我的 php 代码用于获取

     $query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id"' ");


     $rows = array();

     while($row = mysql_fetch_assoc($query)) {

     $rows[] = $row;
     }

     echo json_encode($rows);
4

8 回答 8

2

此行有错误,此:

$question_id"' "

应该

$question_id . "'"
于 2012-09-24T09:50:35.627 回答
0

您应该在 url 中用 & not 分隔 get 变量。

于 2012-09-24T09:50:14.097 回答
0

那是因为你应该在 url 参数之间使用&而不是,

http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1

$survey_id = mysql_real_escape_string($_GET['survey_id']);
$question_id = mysql_real_escape_string($_GET['question_id']);
于 2012-09-24T09:50:21.900 回答
0

GET 参数通常用&not分隔,。所以你的链接应该看起来更像这样:

http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1

另外,请注意 GET 变量不会自动转换为 PHP 变量。您需要从$_GET数组中拉出它们:

$survey_id = $_GET['survey_id']

于 2012-09-24T09:50:26.527 回答
0

您没有传递在 url 中分隔的值逗号。您在 url 中使用 &

http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1

于 2012-09-24T09:50:28.357 回答
0
 $query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id"'");

您忘记了在之后连接字符串的要点$question_id->这应该可以解决您的问题:

$query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id."'");

无论如何,还要考虑清理您的 url-inputs -> http://xkcd.com/327/

于 2012-09-24T09:51:05.560 回答
0
 $query = mysql_query("SELECT * from survey_Answers where survey_Id='".$survey_id."' AND question_Id='".$question_id."' ");

少了一个点!

于 2012-09-24T09:51:32.123 回答
0

URL 和 QUERY 都是错误的

http://myserver.com/emrapp/surveyAnswersScreenOne.php?survey_id=1&question_id=1

$question_id . "' "
于 2012-09-24T09:52:01.260 回答