PDA

View Full Version : [PHP] A few errors...



Topps
05-01-2008, 04:03 PM
Hey guys, I have a few little errors in my grid.save.php file, these are the errors...

Warning: preg_match_all() [function.preg-match-all (http://localhost/Loading.FM/homes/function.preg-match-all)]: Unknown modifier 'a' in localhost\homes\grid.save.php on line 8

Warning: Invalid argument supplied for foreach() in localhost\homes\grid.save.php on line 14

...obviously its a problem with 2 certain codes, preg_match_all() and foreach() I don't know what is wrong though.

Here is my file:


<?php
require_once "grid.config.php";
// Call the grid.config.php file.

$data = $_POST['object_data'];
// Assign the object_data post to the $data variable

preg_match_all("/(.*)/imU", $data, $parsed, PREG_PATTERN_ORDER);
// Match all instances of the , tags and their contents.

$parsed_data = array();
// Create an empty array

foreach ($parsed[1] as $data) // Loop through the parsed array
{
$parsed_data[] = $data;
// Add each objects contents to the new array we just created
$tags = array(
"id",
"title",
"src",
"width",
"height",
"top",
"left",
"zindex"
);
// Array of all allowed object tags

$all_objects = array();
// New array

foreach ($parsed_data as $data) // Run through each object array
{
$object = array();
// Create temp new array

foreach ($tags as $tag) // Run through valid tags
{
preg_match_all("/[$tag](.*)[/$tag]/imU", $data, $parse, PREG_PATTERN_ORDER);
// Get contents of tag from current object

$object[] = $parse[1][0]; // Add contents to the object array
}

$all_objects[] = $object; // Add the object array to a all_objects array
}
$assoc = array(); // Create empty array

foreach ($all_objects as $object => $attribute) // Loop through the all_objects array
{
$info = array(); // Create new info array

$info['obj_id'] = $attribute[0];
$info['obj_title'] = $attribute[1];
$info['obj_src'] = $attribute[2];
$info['obj_width'] = $attribute[3];
$info['obj_height'] = $attribute[4];
$info['obj_top'] = $attribute[5];
$info['obj_left'] = $attribute[6];
$info['obj_zindex'] = $attribute[7];
// Add all the attributes to the info array

$assoc[] = $info; // Add the current info array to the newly created assoc array.
}
foreach ($assoc as $object) // Loop through the assoc array.
{
if (substr($object['obj_title'], 0, 8) != "deleted_") // If the object was not deleted in the script...
{
$find_object = mysql_query("SELECT * FROM `object` WHERE `obj_id` = '" . $object['obj_id'] . "'");
// Search for the object in the database

if (mysql_num_rows($find_object) == 1) // If found...
{
mysql_query("LOCK TABLES `object` WRITE"); // Lock the tables...

mysql_query(
"UPDATE `object` SET `obj_top` = '" . $object['obj_top'] . "'" .
", `obj_left` = '" . $object['obj_left'] . "', `obj_zindex` = '" . $object['obj_zindex'] . "' WHERE `obj_id` = '" . $object['obj_id'] . "'");
// Update object entry...

mysql_query("UNLOCK TABLES"); // Unlock the tables...
}
else // Else if no entry found...
{
mysql_query("LOCK TABLES `object` WRITE"); // Lock the tables...

mysql_query(
"INSERT INTO `object` " .

"(`obj_id`, " .
"`obj_title`, " .
"`obj_src`, " .
"`obj_width`, " .
"`obj_height`, " .
"`obj_top`, " .
"`obj_left`, " .
"`obj_zindex`) " .

"VALUES " .
"('" . $object['obj_id'] . "', " .
"'" . $object['obj_title'] . "', " .
"'" . str_replace(" ", "%20", $object['obj_src']) . "', " .
"'" . $object['obj_width'] . "', " .
"'" . $object['obj_height'] . "', " .
"'" . $object['obj_top'] . "', " .
"'" . $object['obj_left'] . "', " .
"'" . $object['obj_zindex'] . "')"); // Insert new entry of the object in the database

mysql_query("UNLOCK TABLES"); // Unlock the tables...
}
}
else // Else if the object was deleted in the drag and drop script...
{
mysql_query("LOCK TABLES `object` WRITE"); // Lock the tables...

mysql_query("DELETE FROM `object` WHERE `obj_id` = '" . $object['obj_id'] . "'");
// Delete the deleted object from the database...

mysql_query("UNLOCK TABLES"); // Unlock the tables...
}
}
preg_match_all("/(.*)/imU", $data, $parsed, PREG_PATTERN_ORDER);
// Match all the toggle boxes.

$parsed_data = array(); // Create parsed data array

foreach ($parsed[1] as $data) // Loop through matched toggle boxes...
{
$parsed_data[] = $data; // And add them to the parsed data array
}

$tags = array(
"id",
"value"
);
// Array of allowed toggle tags

$all_objects = array(); // Create new all objects array

foreach ($parsed_data as $data) // Loop through toggle parsed data...
{
$object = array(); // Create temp new array

foreach ($tags as $tag) // Loop through each tag list
{
preg_match_all("/[$tag](.*)[/$tag]/imU", $data, $parse, PREG_PATTERN_ORDER);
// Match contents of the tag in the toggle tag...

$object[] = $parse[1][0]; // Add tag info to the object array
}

$all_objects[] = $object; // Add the temp object array to the all_objects array
}

$assoc = array(); // Create new assoc array.

foreach ($all_objects as $object => $attribute) // Loop through all_objects array...
{
$info = array(); // Create temp new array

$info['tog_id'] = $attribute[0];
$info['tog_value'] = $attribute[1];
// Add to the info array the toggle id and value

$find_object = mysql_query("SELECT * FROM `toggle` WHERE `tog_id` = '" . $info['tog_id'] . "'");
// Check for toggle entry.

if (mysql_num_rows($find_object) == 1) // If the toggle id is in the database...
{
mysql_query("LOCK TABLES `toggle` WRITE"); // Lock the tables...

mysql_query("UPDATE `toggle` SET `tog_value` = '" . $info['tog_value'] . "' WHERE `tog_id` = '" . $info['tog_id'] . "'");
// Update toggle entry...

mysql_query("UNLOCK TABLES"); // Unlock the tables.
}
}
}
?>

Thanks for any help in advance everyone! :)

Want to hide these adverts? Register an account for free!