Levinax Posted April 12, 2006 Share Posted April 12, 2006 so i have a script where i can update entries in my database. i have all the SQL worked out to where i know that hitting the submit button successfully updates the information in the database. however, the information on the form on the current page still displays the old information. if i hit F5 and refresh the page, it comes up with the new info, but i was wondering if there was a way to do it so it would automatically refresh after hitting the submit button?here is my function... i know its got to be something with my data flow... but i am not a programmer (my boss seems to think i am though =\ )[code]function edit_form($db, $hostname){if (isset($hostname)) { echo "Update Entry Form"; $edittype = "update"; //query db and put results in array to populate form $lkup = "SELECT * FROM info WHERE hostname = '$hostname'"; $editqry = pg_query($db, $lkup); $editres = pg_fetch_array($editqry); }else { echo "Add New Form"; $edittype = "insert"; }echo"<BR>";echo"<BR><table> <form method=POST name=input> <tr><td>Hostname:</td><td> <input type=\"text\" name=\"host\" value=\"$hostname\"></td></tr> <tr><td>MAC:</td><td> <input type=\"text\" name=\"mac\" value=\"$editres[mac_address]\"></td></tr> <tr><td>OS:</td><td> <input type=\"text\" name=\"os\" value=\"$editres[os]\"></td></tr> <tr><td>SP:</td><td> <input type=\"text\" name=\"sp\" value=\"$editres[service_pack]\"></td></tr> <tr><td>CPU:</td><td> <input type=\"text\" name=\"cpu\" value=\"$editres[processor]\"></td></tr> <tr><td>RAM:</td><td> <input type=\"text\" name=\"ram\" value=\"$editres[ram]\"></td></tr> <tr><td>HDD:</td><td> <input type=\"text\" name=\"hdd\" value=\"$editres[hard_drive]\"></td></tr> <tr><td>Optical:</td><td> <input type=\"text\" name=\"cdr\" value=\"$editres[optical_type]\"></td></tr> <tr><td>FDD:</td><td> <input type=\"text\" name=\"fdd\" value=\"$editres[floppy]\"></td></tr> <tr><td>Dell Tag:</td><td> <input type=\"text\" name=\"dell\" value=\"$editres[dell_service_tag]\"></td></tr> <tr><td>Location:</td><td> <input type=\"text\" name=\"locat\" value=\"$editres[location]\"></td></tr> <tr><td>Store:</td><td> <input type=\"text\" name=\"store\" value=\"$editres[store]\"></td></tr> <tr><td>Dept:</td><td> <input type=\"text\" name=\"dept\" value=\"$editres[dept]\"></td></tr> <tr><td>Comments:</td><td> <input type=\"text\" name=\"comment\" value=\"$editres[comments]\"></td></tr> <input type=hidden name=edit value=$edittype> <tr><td colspan=\"2\" align=\"center\"><input type=submit value=\"Submit\" action=\"$updqry\" onlcick=\"edit_form($db, $hostname)\"></td></tr\> </form></table>";if($edittype = "update"){ $updtbl = "UPDATE info SET mac_address='$_POST[mac]', os='$_POST[os]', service_pack='$_POST[sp]', processor='$_POST[cpu]', ram='$_POST[ram]', hard_drive='$_POST[hdd]', optical_type='$_POST[cdr]', floppy='$_POST[fdd]', dell_service_tag='$_POST[dell]', store='$_POST[store]', dept='$_POST[dept]', location='$_POST[locat]', comments='$_POST[comment]' WHERE hostname = '$hostname'"; }else if($edittype = "addnew"){ $updtbl = "INSERT INTO info VALUE '$_POST[host]', '$_POST[mac]', '$_POST[os]', '$_POST[sp]', '$_POST[cpu]', '$_POST[ram]', '$_POST[hdd]', '$_POST[cdr]', '$_POST[fdd]', '$_POST[dell]', '$_POST[store]', '$_POST[dept]', '$_POST[comment]', '$_POST[locat]'"; }$updqry = pg_query($db, $updtbl);}[/code] Quote Link to comment Share on other sites More sharing options...
earl_dc10 Posted April 13, 2006 Share Posted April 13, 2006 hi, try changing[code]<form method=POST name=input>[/code]to[code]<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" name="input">[/code] Quote Link to comment Share on other sites More sharing options...
Levinax Posted April 13, 2006 Author Share Posted April 13, 2006 [!--quoteo(post=364234:date=Apr 12 2006, 05:12 PM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 12 2006, 05:12 PM) [snapback]364234[/snapback][/div][div class=\'quotemain\'][!--quotec--]hi, try changing[code]<form method=POST name=input>[/code]to[code]<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="POST" name="input">[/code][/quote]nope, that gives me the following error:[code][Thu Apr 13 09:34:16 2006] [error] PHP Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in /home/test/public_html/test/test4.php on line 262[/code] Quote Link to comment Share on other sites More sharing options...
earl_dc10 Posted April 13, 2006 Share Posted April 13, 2006 are you echoing the form inside of php? if you are try this :[code]echo ' ....<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="input">[/code]hope that helps! Quote Link to comment Share on other sites More sharing options...
Levinax Posted April 13, 2006 Author Share Posted April 13, 2006 [!--quoteo(post=364512:date=Apr 13 2006, 11:26 AM:name=earl_dc10)--][div class=\'quotetop\']QUOTE(earl_dc10 @ Apr 13 2006, 11:26 AM) [snapback]364512[/snapback][/div][div class=\'quotemain\'][!--quotec--]are you echoing the form inside of php? if you are try this :[code]echo ' ....<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="input">[/code]hope that helps![/quote]yes, i am echoing it in PHP, and that gives me the same parse error. Quote Link to comment Share on other sites More sharing options...
earl_dc10 Posted April 13, 2006 Share Posted April 13, 2006 ensure that your echo statement uses single quotes for the echoing ', if you have doubles " you'll need to do an escape slash[code]echo "<form action=\"".$_SERVER['PHP_SELF']."\" method=\"POST\" name=\"input\">[/code] 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.