2012-07-26 61 views
0

我正在使用PHP queryString传递var但它没有得到值的queryString不工作的PHP网站

http://celeritas-solutions.com/emrapp/surveyDescription.php?user_id=ali40

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host."); 
mysql_select_db($database, $linkID) or die("Could not find database."); 

if (!function_exists('json_encode')) 
{ 
    function json_encode($a=false) 
    { 
     if (is_null($a)) return 'null'; 
     if ($a === false) return 'false'; 
     if ($a === true) return 'true'; 
     if (is_scalar($a)) 
     { 
      if (is_float($a)) 
      { 
       // Always use "." for floats. 
       return floatval(str_replace(",", ".", strval($a))); 
      } 

      if (is_string($a)) 
      { 
       static $jsonReplaces = array(array("\\", "/", "\n", "\t", "\r", "\b", "\f", '"'), array('\\\\', '\\/', '\\n', '\\t', '\\r', '\\b', '\\f', '\"')); 
       return '"' . str_replace($jsonReplaces[0], $jsonReplaces[1], $a) . '"'; 
      } 
     else 
      return $a; 
     } 

     $isList = true; 
     for ($i = 0, reset($a); $i < count($a); $i++, next($a)) 
     { 
      if (key($a) !== $i) 
      { 
       $isList = false; 
       break; 
      } 
     } 

     $result = array(); 
     if ($isList) 
     { 
      foreach ($a as $v) $result[] = json_encode($v); 
      return '[' . join(',', $result) . ']'; 
     } 
     else 
     { 
      foreach ($a as $k => $v) $result[] = json_encode($k).':'.json_encode($v); 
      return '{' . join(',', $result) . '}'; 
     } 
    } 
} 

$user_id=$_GET['user_id']; 
echo($user_id); 

$query = mysql_query("SELECT s.*, u.user_id FROM survey_master AS s JOIN user_profile AS u on u.user_id = s.user_id where s.user_id='".$user_id."' "); 

$rows = array(); 
while($row = mysql_fetch_assoc($query)) { 
    $rows[] = $row; 
} 

echo json_encode($rows); 
+0

;'这个......你让空或未定义指数错误? – swapnilsarwe 2012-07-26 07:22:18

+0

您能否只发布相关代码? – 2012-07-26 07:22:29

+0

var_dump($ _GET);查看获取请求中的内容。 – AlphaMale 2012-07-26 07:23:43

回答

0

$ user_ID的未设置。 要设置这样的:

当你`回声($ user_ID的)
<?php 
    $user_id = $_REQUEST['user_id']; 
    // OR use Strict the super global GET 
    $user_id = $_GET['user_id']; 
    .... 
+0

不知道为什么这被认为是一个修复 - $ _GET ['user_id']已被使用后的json_encode - 使用$ _REQUEST不应该修复任何问题(理论上!)。 – williamvicary 2012-07-26 08:43:43

0

为什么你不先试试这个?

<?php 
echo $_GET['user_id']; 
?> 

这将工作,所以你可以通过消除找到有问题的代码。

0

试试看var_dump($_GET);看看你的_GET数组里有什么。

确定查询返回s.user_id = ali40

尝试查询的结果的var_dump过,或var_dump(mysql_errors());得到任何MySQL的错误

+0

是的我当我通过html文本框访问此代码通过文本框发送数据然后它的作品,但它不工作的url – user1553768 2012-07-26 07:25:57

+0

@Stu已经完成json_encode函数后。 – williamvicary 2012-07-26 07:28:29

+0

yes by var_dump($ _GET);它显示的数据 – user1553768 2012-07-26 07:28:38