I am sending a serialized json string from Jquery form to a form_handler.php post. I am getting this error message on the AJAX response in firebug:
"Connected to Taskostrueresource(4) of type (mysql result)
<br />
<b>Warning</b>: [json] (php_json_encode) type is unsupported, encoded as null in <b>/Library/WebServer/Documents/form_handler.php</b> on line <b>18</b><br />
null"
The reason there are 2 results is one is to insert the data into the database and the 2nd result is to return the list as a response to the web page. So I'm assuming that the print statement would be the response to the AJAX. Do I need to do a json_decode instead? I don't know if the error is a coding issue. The doctype is <HTML5> The database encoding is utf8_genera_cil. You can see my demo page at:
http://janisrough.dyndns.biz/todo8.html

Here is my AJAX form_handler:

ini_set("max_execution_time",'800');
error_reporting(E_ALL^E_NOTICE);
include("db.php");

$task= $_POST['todo'];
$date =$_POST['date'];
$name = $_POST['name'];
$sql = "INSERT INTO task(todo, date, name) values('$task','$date','$name') ";
$result = mysql_query($sql);
    if ( !$result ) {die("<font style='color:red'>Invalid query:</font>" . mysql_error() . "<br>$sql");}


$sql2="SELECT todo FROM task WHERE todo IS NOT NULL";
$result2= mysql_query($sql2);
    if ( !$result2 ) {die("<font style='color:red'>Invalid query:</font>" . mysql_error() . "<br>$sql");} 
var_dump($result2);
print (json_encode($result2));
echo $result2;

thanks,

    You can't JSON encode a MySQL result set, any more than any other resource (what would the browser do with it anyway?)

    Presumably you want to fetch some data from the result set and encode that.

      Instead of this

      $sql2="SELECT todo FROM task WHERE todo IS NOT NULL";
      $result2= mysql_query($sql2);
          if ( !$result2 ) {die("<font style='color:red'>Invalid query:</font>" . mysql_error() . "<br>$sql");}
      var_dump($result2);
      print (json_encode($result2));
      echo $result2; 
      

      enode the array of result which contains the whole data

      that is some thing like this

      $sql2="SELECT todo FROM task WHERE todo IS NOT NULL";
      $result2= mysql_query($sql2);
      $arr_result = array();
          if ( !$result2 ) {die("<font style='color:red'>Invalid query:</font>" . mysql_error() . "<br>$sql");}
      while($result_of_result2= mysql_fetch_assoc($result2))
      {
      $arr_result = $result_of_result2
      }
      var_dump($arr_result);
      print (json_encode($arr_result));
       

      this is what the Weedpacket wants to tell

      You can't JSON encode a MySQL result set, any more than any other resource (what would the browser do with it anyway?)

      Presumably you want to fetch some data from the result set and encode that.

        ok thanks, so I was confusing the post result with the mysql resource, thanks again

          Write a Reply...