Jump to content

how to store value from a array into one variable?


friedice

Recommended Posts

hello, um i got a form that stored an array of variables upon users clicks.

it submits to another page fine as an array and i can print them using

if(!empty($_POST['langSpoken'])) {

    echo "\n<p><strong>You selected the following LangSpoken:</strong></p>\n<ul>";

    foreach($langSpoken as $lang) {

      // exclude any items with chars we don't want, just in case someone is playing
      if(!preg_match('/^[-A-Z0-9\., ]+$/iD', $lang)) continue;

      // print the lang
      echo "\n\t<li>" . htmlspecialchars($lang) . "</li>";
    }
    echo "\n</ul>";

  } 
  else {
    echo "\n<p>No items selected</p>";
  }

 

it prints a list a of array like

  • english
  • spanish

 

but i need to store each one in one variable so i can store in a database

is there a way?

thx

Link to comment
Share on other sites

You don't want to store all the values in one record within the database, that would be a poor design decision. Instead, each of these values should have there own row. You can then use another items 'id' to relate them if need be.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.