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
https://forums.phpfreaks.com/topic/146087-array-troubles-name-_postname/
Share on other sites

Waste of memory space using variables for each item in the $_POST, $_GET array.

Use the data within the array

 

foreach($_POST as $key => $val) {
   $_POST[$key] = mysql_real_escape_string($_POST[$key]);
}

mysql_query("INSERT INTO table SET name='".$_POST['name']."'");

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.