BrianM Posted May 9, 2008 Share Posted May 9, 2008 To start things off I'll post the source I have at this point. page displaying table and it's content <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> <?php mysql_connect("localhost", "brian", ""); mysql_select_db("example"); function returnheaders() { $sql = mysql_query("SELECT * FROM example WHERE ID=1") or die(mysql_error()); $array = mysql_fetch_array($sql); //print_r($array); foreach($array as $key => $value) { if(!is_numeric($key) && $key != "ID") { echo("<td id=\"header_$key\">$key</td>\n"); } } } function returndata() { $sql = mysql_query("SELECT * FROM example"); while($row = mysql_fetch_array($sql)) { echo("<tr id=\"dataset_row".$row['ID']."\">\n"); foreach($row as $key => $value) { if(!is_numeric($key) && $key != "ID") { echo("<td id=\"".$key.$row['ID']."\" nowrap><a id=\"".$key."_".$row['ID']."_value\" href=\"javascript:edit_row(".$row['ID'].");\">".$value."</a></td>\n"); } } echo("</tr>\n"); } } function loaddynamicjava() { echo("<script type=\"text/javascript\">\nvar readylight = true;\nfunction edit_row(row) {\nvar currentval;\n"); $sql = mysql_query("SELECT * FROM example WHERE ID=1") or die(mysql_error()); $array = mysql_fetch_array($sql); foreach($array as $key => $value) { if(!is_numeric($key) && $key != "ID") { echo("currentval = document.getElementById(\"".$key."_\"+row+\"_value\").innerHTML;\n"); echo("document.getElementById(\"".$key."\"+row).innerHTML = "); if($key == "PermitProcess") echo("'<input type=\"button\" name=\"save\" value=\"Save\" onClick=\"savedata('+row+');\">"); else echo("'"); echo("<input type=\"text\" id=\"".$key."_'+row+'\" name=\"".$key."_'+row+'\" value=\"'+currentval+'\" />';\n"); } } echo("}\nfunction savedata(row) {\nif(!ready) { alert(\"System is still saving other data\"); return; }\nready = false;\nvar currentdata;"); foreach($array as $key => $value) if(!is_numeric($key)) if($key == "ID") echo("document.getElementById(\"ID\").value = row;\n"); else echo("document.getElementById(\"".$key."\").value = document.getElementById(\"".$key."_\"+row).value;\n"); echo("document.getElementById(\"theform\").submit();\n"); foreach($array as $key => $value) if(!is_numeric($key) && $key != "ID") { echo("currentdata = document.getElementById(\"".$key."_\"+row).value;\n"); echo("document.getElementById(\"".$key."\"+row).innerHTML = '<a href=\"javascript:edit_row('+row+');\" id=\"".$key."_'+row+'_value\">'+currentdata+'</a>';\n"); } //echo("}"); echo("}\nfunction nowready() { ready = true; }</script>"); } function returnformfields() { $sql = mysql_query("SELECT * FROM example LIMIT 1"); $array = mysql_fetch_array($sql); foreach($array as $key => $value) if(!is_numeric($key)) echo("<input type=\"hidden\" name=\"".$key."\" id=\"".$key."\">\n"); } ?> <?php loaddynamicjava(); ?> </head> <body> <table border="1" cellpadding="0" cellspacing="0"> <tr class="header"><?php returnheaders(); ?></tr> <?php returndata(); ?> </table> <form action="update.php" method="post" target="hiddenframe" name="theform" id="theform"> <?php returnformfields(); ?> </form> <iframe src="about:blank" style="display: none;" name="hiddenframe" id="hiddenframe" onLoad="nowready();">This Page Requires iFrames Which Your Browser Does not support</iframe> </body> </html> update page the form sends to <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <?php if (isset($_POST['save'])) { mysql_query("UPDATE `example` SET `Required` = '$value', `Required` = '$value' WHERE `ID` = '1'"); } ?> <body> </body> </html> I'm not sure what kind of mess I've got myself into here, but is what I'm trying to do is figure out whether or not is if(isset($_POST['save'])) is needing to be set to something else, maybe the field name being updated in the table?? ??? It updates in the current table but if I refresh or leave the page it's back to it's original state, and also, it wont save content to the database, which is the main issue I'm having here, not being able to figure out how to write my update.php file. I hope somebody can hint me on what to fix. -Brian Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 9, 2008 Author Share Posted May 9, 2008 Oh, and if anyone would like me to write the database structure out so they can try this out, I will gladly write an .sql file for you, as I did not take the time to do so just yet, but will upon request, if needed. Quote Link to comment Share on other sites More sharing options...
radar Posted May 9, 2008 Share Posted May 9, 2008 You don't need to set Required twice.. so change it to this as a test (this is how I do mine to ensure stuff is getting set)... if (isset($_POST['save'])) { $sql = "UPDATE example SET 'Required' = '$value' WHERE ID = '1'"); echo $sql; mysql_query($sql); } Also why use an iframe?.. Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 9, 2008 Author Share Posted May 9, 2008 Also why use an iframe?.. For development purposes. And I get: Parse error: parse error in C:\Program Files\Apache Group\Apache2\htdocs\examples\update.php on line 11 on line 11, which is: $sql = "UPDATE example SET 'Required' = '$value' WHERE ID = '1'"); Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 9, 2008 Author Share Posted May 9, 2008 Never mind, I see there was an '(' left out, but I still wont update in the database :| Boy this is fun. I don't know why it wont update... Any suggestions?? Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 9, 2008 Author Share Posted May 9, 2008 Bump. Quote Link to comment Share on other sites More sharing options...
BrianM Posted May 12, 2008 Author Share Posted May 12, 2008 I was on a short vacation, but am back now. Well I'm back to work on this problem I'm having. I now have the following, leaving out the if statement just to see if it will update the content in the database when i run the script alone, and it doesn't, which is really weird. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Untitled Document</title> </head> <?php mysql_connect("localhost", "brian", "*password*"); mysql_select_db("example"); //if (isset($_POST['save'])) { $sql = "UPDATE example SET 'Required' = 'NO' WHERE ID = '1'"; mysql_query($sql); //} ?> <body> </body> </html> Did I do something wrong, or leave anything out that I should have in here. It just plain wont update, period. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.