Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8484851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:29:09+00:00 2026-06-10T20:29:09+00:00

I am new to PHP & JSON, and based on a tutorial I made

  • 0

I am new to PHP & JSON, and based on a tutorial I made a simple web service which returns the contents of a table of a mysql db.

The output is in JSON and the database caracter set is UTF-8. my problem is that when I try to run this it throws me a 404 error, and doesn’t show me where the error is. Any idea what might be wrong?

The PHP file is the following:

<?php
  ini_set("display_errors", 1);
  error_reporting(E_ALL);
  $link = mysql_connect($mysql_host,$mysql_user,$mysql_password) or die("cannot connect to the DB");
  mysql_select_db($mysql_database,$link);
  $query = "select...";
  $result=mysql_query($query) or die (mysql_error("error "));
  $num=mysql_numrows($result);
  $rows=array();
  while($r=mysql_fetch_assoc($result)){
      $rows[]=$r;
  }
  echo json_encode($rows);
?>

Any Idea? Thanks in advance

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T20:29:10+00:00Added an answer on June 10, 2026 at 8:29 pm

    Add following line before json_encode()

    header('Content-type: application/json');
    

    That should solve your problem.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

<?php session_start(); require_once('JSON.php'); $url= 'http://ajax.googleapis.com/ajax/services/search/web?rsz=large&v=1.0&q='. $_POST['searchquery'].'&key=ABQIAAAA4oH5MwaexHdhZg4UWRNB1RT2yXp_ZAY8_ufC3CFXhHIE1NvwkxTzUf4N43torAasiY6JD5CaJS6n7Q&userip=http://localhost/'; echo $url; // use fopen and fread to
I am trying to use a PHP form (new.php) to update 2 MySQL tables
New to PHP and MySQL, have heard amazing things about this website from Leo
I'm a bit new to web services. I followed this tutorial and built a
I am very very new at PHP and I don't even know JSON. Also,
JSON URL : http://en.wikipedia.org/w/api.php?format=json&action=opensearch&search= +str+&namespace=0&suggest= Here str may be any 2-3 char for an
I'm a spanking new developer to the PHP & SQL scene. I've only done
I'm quite new to Zend & JSON, however I have the need to learn.
I'm taking some json, made by OpenLibrary.org, and remake a new array from the
I have to return data fetched from MySQL table into a php file as

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.