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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:57:26+00:00 2026-06-01T23:57:26+00:00

this is driving me crazy so any help is much appreciated. I am posting

  • 0

this is driving me crazy so any help is much appreciated.

I am posting records with name=opc[1] cat[2] etc. Ideally this would created an array. When I print_r the posted data, it prints what looks like an array though with ticks and slashes around the keys.

However, when I set a variable, $array or whatever equal to the array, print_r($array) returns 0. Echo returns Array.

Possibly related to this, when I try to do foreach on the array, it gives an invalid argument error. What do I need to do to the posted data so that I can set it to a variable and use it as a valid array. I’ve tried various combinations of implode, explode and stripslashes to put it into better form but only the $_POST prints out in print_r. Implode generates an error. Explode creates an Array with just 1 item.

Here is print_r($_POST[‘opc’]);

Array ( [\'0\'] => dog [\'1\'] => cat [\'2\'] => mouse [\'3\'] => chicken [\'4\'] => runner [\'5\'] => )

What do I need to do to work with this?

form code (first two records):

<tr><form action="editcats.php" method="post"><td align="right">Existing:</td><td align="left"><input type="text" size="12" name="ocp[0]" value="dog"><input type="hidden" name="id[0]" value="1"></tr>
<tr><td align="right"></td><td align="left"><input type="text" size="12" name="ocp[1]" value="cat"><input type="hidden" name="id[1]" value="2"><input type="submit" value="submit"></form></tr>
  • 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-01T23:57:28+00:00Added an answer on June 1, 2026 at 11:57 pm

    After reviewing your HTML source code, it appears that you are mixing up the method on how to pass an array variable to $_POST. You shouldn’t have two elements with the same ‘name’ either, even if you wish them to post to the same array. Either rectify your method for entering data into the array variable, or name the elements differently.

    Remove the indices from your name attribute and try running your form again.

    See this related question for some help as well.

    <input type="text" size="12" name="ocp[]" value="cat"><input type="hidden" name="id[]" value="2"><input type="submit" value="submit"></form></tr>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This is driving me crazy , so any help would be awesome: My html
This is driving me crazy, so any help will be appreciated. I am developing
I'm driving myself crazy trying to understand Expressions in LINQ. Any help is much
This is driving me crazy and has resulted in lost work (not much, at
Please help - this is driving me crazy... I have a number of lines
This is driving me crazy. Very grateful if someone could help me out! Problem:
This is driving me crazy. I have this one php file on a test
This is driving me crazy. I'm not going to take it anymore. I'm going
This is driving me crazy, so... When resizing image to small thumbnail, resulting image
This is driving me crazy. I have a very simple user control: public int?

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.