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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:53:48+00:00 2026-06-10T07:53:48+00:00

I’ve tried to implement Tagit to my website, but I can’t get the array

  • 0

I’ve tried to implement Tagit to my website, but I can’t get the array of tags to behave in a way I want it to…

I’ve googled and tried a bunch of different things but cant get it to work.

This is my JavaScript function:

function saveSkillTags( tags ) {
$.ajax({
  type: "POST",
  dataType: "json",
traditional: true,
  url: "/../includes/ajaxController.php",
  data: {actionCommand : "SAVE_SKILL_TAGS", tags : tags }
}).done(function( res ) {
    console.debug('klar');
});
}

Console.debug showed me that the "tags" array looks like this:

[Object { label="php",  value="php",  element=[1],  mer...}, Object { label="ajax",  value="ajax",  element=[1],  mer...}, Object { label="javascript",  value="javascript",  element=[1],  mer...}, Object { label="jquery",  value="jquery",  element=[1],  mer...}]

It posts to my ajaxController which has this code:

if( $actionCommand == 'SAVE_SKILL_TAGS' ) {
require_once( dirname( __FILE__ ).'/../classes/stuff.class.php' );
$list = new UserStuff();
$list->saveSkillTags( $utility->getUserId(), $_POST['tags'] );
}

So, so far so good…

Then in stuff.class.php I have the function "saveSkillTags". Here is the problem…
I’ve tried to encode and decode json, and tried it just without json, but I can’t get anything to work…
Here is the function:

function saveSkillTags( $userId, $tags ) {
    $dbCon = new DBConnection();
    //$tags = json_decode($tags);
    error_log($tags);
    foreach ( $tags as $tag => $value ) {
        $skillTag = $dbCon->escape( $value );
        $query = "INSERT INTO skilltag SET ";
        $query .= "User_fk=".$userId;
        $query .= ", TagName='".$skillTag."'";
        $dbCon->execute( $query );
        error_log($query);
    }
    
    mysql_close();
    echo 'true';
}

As you see, I error_log $tags.

And when I run this setup I get two errors. The first one is the $tags var, and the second one is generated.

[24-Aug-2012 22:28:35] [object Object]

[24-Aug-2012 22:28:35] PHP Warning:  Invalid argument supplied for foreach() in C:\Users\...\classes\stuff.class.php on line 103

I’ve fiddled with this now for several hours and starting to doubt my programming skills heavily…

Please help me get back on track, even a hint would be much appreciated!

  • 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-10T07:53:50+00:00Added an answer on June 10, 2026 at 7:53 am

    What you need to do is pass the data inside tags as JSON – currently it is being posted a object. In order to do this use JSON.stringify()

    $.ajax({
      type: "POST",
      dataType: "json",
    traditional: true,
      url: "test.php",
      data: {actionCommand : "SAVE_SKILL_TAGS", tags : JSON.stringify(tags) }
    }).done(function( res ) {
        alert(res);
    });
    });
    

    JSON.stringify is available in most modern browsers (but maybe not in some older ones). Basically it takes a Javascript object and converts it into a JSON string. Note that when stringifying, it might escape quotes and stuff, to ensure that the resultant JSON is valid.

    So in the PHP script, if you do a print_r($_POST['tags']), you should see how the JSON looks and then you can adjust your code accordingly.

    UPDATE

    Try the following foreach loop:

    foreach ( $tags as $tag => $value ) 
    { 
        $skillTag = $value->value; 
        $query = "INSERT INTO skilltag (User_fk, TagName) values ('".$userId."','".$skillTag."')"; 
        $dbCon->execute( $query ); 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to count how many characters a certain string has in PHP, but
I have a French site that I want to parse, but am running into
I want to construct a data frame in an Rcpp function, but when I
I have just tried to save a simple *.rtf file with some websites and
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I want use html5's new tag to play a wav file (currently only supported

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.