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 8312655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:14:13+00:00 2026-06-08T20:14:13+00:00

i need help to parsing json data to mysql. my code its not work,

  • 0

i need help to parsing json data to mysql. my code its not work, this is my code.

<?php
$server = "localhost";
$username = "root";
$password = "12345";
$database = "json";
mysql_connect($server,$username,$password) or die("Failed");
mysql_select_db($database) or die("Database Failed");

$url = "http://demo.miliarta.com/cityapi/all/?dealerid=TEN000005&user=dealer&passwd=dealer&cityid=316";
$string = file_get_contents($url);
$arr = json_decode($string, true);

//array instances specific to json items
$id = $arr["cityid"];
$id2 = $arr["stateid"];
$id3 = $arr["cityname"];
$id4 = $arr["statename"];
$s=0;
//Enumerating Array index
foreach($arr as $item=> $value){
    $s=count($value); // WIN
}
echo $s;
//suck the array for loop
for($i=0;$i<$s;$i++){
    $cityid= $id[0];
    $stateid = $id2[$i];
    $cityname = $id3[$i];
    $statename = $id4[0];
    mysql_query("INSERT INTO city (cityid, stateid, cityname, statename) VALUES('$cityid', '$stateid', '$cityname', '$statename')") or die (mysql_error());
}
?>

the problem is on line 22.
Notice: Undefined index: cityid in C:\xampp\htdocs\json\jsontosql.php on line 22
Notice: Undefined index: stateid in C:\xampp\htdocs\json\jsontosql.php on line 23
Notice: Undefined index: cityname in C:\xampp\htdocs\json\jsontosql.php on line 24
Notice: Undefined index: statename in C:\xampp\htdocs\json\jsontosql.php on line 25
4Table ‘json.city’ doesn’t exist

tq for help.

  • 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-08T20:14:14+00:00Added an answer on June 8, 2026 at 8:14 pm

    Fixed it for you. Your looping is wrong, you need to look on $arr first to get each rows of data.

    Try this:

    <?php
    // Your database configs here
    
    $url = "http://demo.miliarta.com/cityapi/all/?dealerid=TEN000005&user=dealer&passwd=dealer&cityid=316";
    $string = file_get_contents($url);
    $arr = json_decode($string, true);
    
    foreach($arr as $item){
        $cityid = $item['cityid'];
        $stateid = $item['stateid'];
        $cityname = $item['cityname'];
        $statename = $item['statename'];
    
        mysql_query("INSERT INTO city (cityid, stateid, cityname, statename) VALUES('$cityid', '$stateid', '$cityname', '$statename')") or die (mysql_error());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Need help on android. Been having this error Error Parsing data org.json.JSONException: Value <html>
I need help in parsing big Json file: {status:{code:200,text:OK},content:[{proposalId:12536,providerId:1,supervisorName:null,supervisorEmail:lolbroek_13@hotmail.com,hostInstitution:qsd,hostCountry:qsd,hostCity:QSD,hostTypeId:1,title:qsd,status:available,numberStudents:null,description:qsd,categoryId:34,startDate:null,endDate:null,submitDate:null,expectedWorkload:null,purpose:null,workOrganisationId:1,function:null,audienceId:1,preConditions:,certificationGranted:null,deliverables:null,expenses:null,revenue:null,vacancies:null,uploadImg:http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png}, {proposalId:12537,providerId:1,supervisorName:null,supervisorEmail:lolbroek_13@hotmail.com,hostInstitution:qsd,hostCountry:qsd,hostCity:QSD,hostTypeId:1,title:qsd,status:available,numberStudents:null,description:qsd,categoryId:34,startDate:null,endDate:null,submitDate:null,expectedWorkload:null,purpose:null,workOrganisationId:1,function:null,audienceId:1,preConditions:,certificationGranted:null,deliverables:null,expenses:null,revenue:null,vacancies:null,uploadImg:http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png}, {proposalId:12538,providerId:1,supervisorName:null,supervisorEmail:lolbroek_13@hotmail.com,hostInstitution:qsd,hostCountry:qsd,hostCity:QSD,hostTypeId:1,title:qsd,status:available,numberStudents:null,description:qsd,categoryId:34,startDate:null,endDate:null,submitDate:null,expectedWorkload:null,purpose:null,workOrganisationId:1,function:null,audienceId:1,preConditions:,certificationGranted:null,deliverables:null,expenses:null,revenue:null,vacancies:null,uploadImg:http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png}, {proposalId:12539,providerId:1,supervisorName:null,supervisorEmail:lolbroek_13@hotmail.com,hostInstitution:qsd,hostCountry:qsd,hostCity:QSD,hostTypeId:1,title:qsd,status:available,numberStudents:null,description:qsd,categoryId:34,startDate:null,endDate:null,submitDate:null,expectedWorkload:null,purpose:null,workOrganisationId:1,function:null,audienceId:1,preConditions:,certificationGranted:null,deliverables:null,expenses:null,revenue:null,vacancies:null,uploadImg:http:\/\/193.136.60.238\/\/MUTW2012\/core\/img\/internship.png}, ................[etc] I
I need help in retrieving a JSON object and parsing the array into my
Need help writing a script downloads data from google insight using c# this is
I'm currently using json-framework and need some help though parsing some JSON i'm getting
I need help with parsing of JSON feed text returned from Twitter. I need
I need help with parsing json string in Java Android Appl. Text of JSON
Need help parsing... In my code, I have a method that returns url.getHost();. But
I need some help improving this function I made for parsing the links in
I need help with parsing this object: var user = { 10000068485: {id:10000068485,name:Jenan}, 10000099257:

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.