Ok, so basically, I'm setting up a small CMS for a client, that I can now install on any website I run. I use MySQL/PHP as the database/language combo, and have been able to extract the information from the database fine, and I do it like this:
/* Find tables */
$find = "SHOW COLUMNS FROM $page";
$fields = mysql_query($find);
/* Setup data arrays and counter */
$item = array(0 => 'none');
$name = array(0 => 'none');
$count = 1;
$bracket1 = '[';
$paren = ')';
/* Setup check for multiple rows */
$rownum = mysql_query("SELECT * FROM $page");
$numr = mysql_num_rows($rownum);
/* Open Table */
echo "<form method='post' action='/admin/index3.php?page=" . $page . "&numr=" . $numr . "'>\n";
echo "<table>\n";
/* Check for multiple rows */
if ($numr == 1) {
/* If only one row, display contents of row */
while($row = mysql_fetch_assoc($fields)) {
/* Find correct field-name length */
$item = array($count => print_r($row, true));
$place1 = strpos($item[$count], $bracket1, 23);
$place2 = strpos($item[$count], $paren);
$length = strlen($item[$count]) - 23 - ($place2 - $place1) - 7;
$name = array($count => substr($item[$count], 23, $length));
echo "<tr><td><p><b>" . $name[$count] . "</b></p></td>\n";
/* Retrieve contents of field */
$text = mysql_query("SELECT $name[$count] FROM $page") or die(mysql_error());
$text2= mysql_fetch_array($text);
$text3 = stripslashes($text2[$name[$count]]);
/* Print contents of field */
echo "<td><textarea name='$name[$count]text' cols='45' rows='15'>" . $text3 . "</textarea></td></tr>\n";
/* Increase counter */
$count += 1;
}
} else {
/* If multiple rows, display contents of each */
echo "multi row";
}
/* Close Table */
echo "</table>\n";
echo "<input type='submit' value='Save Changes' /></form>\n";
But I've run into problems as far as submitting the changes go...I cant get it to submit the re-typed data, mostly because I can't figure out how to pass the array over...here's my code for that
/* Find tables */
$find = "SHOW COLUMNS FROM $page";
$fields = mysql_query($find);
/* Setup data arrays and counter */
$item = array(0 => 'none');
$name = array(0 => 'none');
$count = 1;
$bracket1 = '[';
$paren = ')';
/* If one row, update that row */
if ($numr == 1) {
/* Cycle through fields */
while ($row = mysql_fetch_assoc($fields)) {
/* Find correct field-name length */
$item = array($count => print_r($row, true));
$place1 = strpos($item[$count], $bracket1, 23);
$place2 = strpos($item[$count], $paren);
$length = strlen($item[$count]) - 23 - ($place2 - $place1) - 7;
$name = array($count => substr($item[$count], 23, $length)); */
$text = addslashes($name[count] . "text");
/* Update text */
$update = "UPDATE $page SET $name[$count] = $text";
echo "$update";
$updater = mysql_query($update);
/* Update Counter */
$counter += 1;
}
$done = true;
} else {
/* If not one row, update each row */
$done = false;
}
if ($done == "true") {
echo "<p>Changes saved. <a href='/admin/index.php' alt='[Go Back]'>Go Back</a> to the main admin page.</p>";
}
Any ideas? Any and all help is appreciated.
Thanks! (I know this may not be the best way to do things, but this is how I've figured them out...feel free to criticize)
--Kyle