Jump to content

Array Troubles -- $name = $_POST[$name];


JREAM

Recommended Posts

Hey,

 

basically Im trying to make this loop act like the statements below this box.

But I keep getting an undefined index so the Array Values aren't reading through I think.

I tried a foreach loop, but my logic must be messed up on getting these arrays right, could anyone help me!

 

So each item is like:

$title = $_POST['title'];

$slug= $_POST['slug'];

etc ..

 

$items = 'title, slug, breadcrumb, keywords, description, content, parent_id, position';

// Make the Array
$values = explode(",", $items);

// Loop Through Each Value
for ($i = 0; $i < count($values); $i++) {
echo $values[$i] . '=' . $_POST[$values[$i]];
}	

 

This one works perfectly, Im testing this and the above on the same page

// This Works but I don't want to use it	
$title = mysql_real_escape_string($_POST['title']);
$slug = mysql_real_escape_string($_POST['slug']);
$breadcrumb = mysql_real_escape_string($_POST['breadcrumb']);
$keywords = mysql_real_escape_string($_POST['keywords']);
$description = mysql_real_escape_string($_POST['description']);
$content = mysql_real_escape_string($_POST['content']);
$parent_id = mysql_real_escape_string($_POST['parent_id']);
$position = mysql_real_escape_string($_POST['position']);

Link to comment
Share on other sites

Hey

 

But I wanted the names also to be generated from the array like this so it generates the table ROW based on my function array list:

INSERT INTO table SET $array[$name]='".$_POST[$array[$val]."'");

 

Because then I can re-use the same thing for my other forms for creating a page.

I don't know how to retrieve the POST form name

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.