HTML页面没有使用PHP脚本从数据库中获取价值

时间:2012-07-26 04:41:12

标签: php javascript mysql

我从mysql数据库获取数据使用php脚本问题是在表中有数据但是当我获取returen时只有

它显示以下错误

Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/content/i/h/u/ihus235/html/cs/emrapp/surveyDescription.php on line 73

[]

HTML CODE

  <html<body>
   <INPUT TYPE = "Text" VALUE ="user_id" NAME = "user_id"> This form allows you to connect to the server.<br>
   <form action="surveyDescription.php" method="post" enctype="multipart/form-data"><br>

   Type (or select) Filename: 
    <input type="submit" value="submit">
    </html>

PHP代码

   <?php 
   $host = "********"; 
   $user = "********"; 
   $pass = "********"; 
   $database = "****"; 

   $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=$_POST['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);

  ?> 

3 个答案:

答案 0 :(得分:1)

<input>放入form标记

<body>

   <form action="surveyDescription.php" method="post" enctype="multipart/form-data"><br>
   <INPUT TYPE = "Text" VALUE ="user_id" NAME = "user_id"> This form allows you
    to connect to the server.<br>
   Type (or select) Filename: 
   <input type="submit" value="submit">
    </form>

</body>

更多语法错误:

<html>标记缺少“&gt;”并且您没有在最后关闭<body>标记

答案 1 :(得分:0)

问题在于

$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");

可能是$ user_id没有任何值。请检查一下。

答案 2 :(得分:-4)

php code

if(isset($_POST['submit'])){ 
 $id=$_POST["id"];
 $name=$_POST["name"]
 $db_host="localhost";
$username="root";
$password="cricket";
$database="my_db";
$db_tb_name="resume";
$db_pid="r_id";
$db_p_name="r_name";
$db_tb_disc="r_doc";

mysql_connect($db_host,$username,$password);
mysql_select_db($database) or die( "Unable to select database");
$query_for_result=mysql_query("SELECT * FROM $db_tb_name WHERE ($db_pid) ='$id' or($db_p_name) ='$name'");

$num=mysql_numrows($query_for_result);
echo $num;
mysql_close();

回复是否有用..
感谢