dtyson2000 Posted December 24, 2006 Share Posted December 24, 2006 Hi Folks...I've grown tired of searching and have tried everything to resolve this. Maybe you can give me a pointer or two?I have a basic "edit" form that pulls a row from a database for editing. That works fine. I also have placed a function into that file (after the form) that returns the new information with an option to further edit. That works fine too.The problem is this: The returned table (from the function added()) with the new information is underneath the form into which I type the new information. I would like for it to replace that form.I've tried some "if" statements with and without "isset" but I just can't get this.Should I make two functions? One for "edit" (into which one puts new info) and one for "added" (which displays the new info with a choice to further edit)?Gosh this is so vague but I'm really embarrassed to post the code for this. It's such a mess. Do you get what I'm asking? Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/ Share on other sites More sharing options...
Jessica Posted December 24, 2006 Share Posted December 24, 2006 "Should I make two functions? One for "edit" (into which one puts new info) and one for "added" (which displays the new info with a choice to further edit)?"From what you explained, I'd try that first. Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/#findComment-147212 Share on other sites More sharing options...
dtyson2000 Posted December 24, 2006 Author Share Posted December 24, 2006 Ok... I tried to clean up my code as best as possible. I hope it's legible.This is what I'm working with. Again, it provides the form with the info to be edited but then, instead of replacing it with the function added(), it adds the contents of the function to the end of the form.I've chopped lots of extraneous stuff out.[code]<?php // get ID for edit $id = $_GET['id']; // Connect to MySQL and Dbase mysql_connect("...", "...", "...") or die(mysql_error()); mysql_select_db("...") or die(mysql_error()); $query = "SELECT * FROM table WHERE id='$id'"; $result=mysql_query($query); $num=mysql_numrows($result); mysql_close(); // get information for edit $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); et cetera... echo " <p align='center'><a href='adminpanel.php'>Return to Admin Panel</a></p> <form action='' method= 'post'> <table width='90%' border='0' align='center' style='margin-bottom:15px;'> et cetera... <tr> <td colspan='8' align='right'><input type='submit' name='ud_update' value='Update'></td> </tr> </table> </form>"; $i++ ; } $ud_id = $_POST['ud_id']; et cetera... function added(){ $id = $_GET['id']; mysql_connect("...","...","..."); mysql_select_db("...") or die("Unable to select database"); $query = "SELECT * from table where id = $id"; $numresults=mysql_query($query); $numrows=mysql_num_rows($numresults); $result = mysql_query($query) or die("Couldn't execute query"); $a = $numrows; while ($row= mysql_fetch_array($result)) { $id = $row["id"]; et cetera... echo " <table width='600px' align='center' style='border: 1px solid #ccc; background-color: #fff; padding: 3px 3px 3px 5px;'> <tr> <td colspan='3' valign='top'><b>Admin</b>: (<a href=\"edit.php?id=$id\">EDIT</a> - <a href=\"del.php?id=$id\">DELETE</a>) </tr> </table> <br>"; } } if ($ud_update){ global $id; mysql_connect("...", "...", "...") or die(mysql_error()); mysql_select_db("...") or die(mysql_error()); $query = "UPDATE table SET ... WHERE id='$id'"; $result = mysql_query($query) or die("Error: ". mysql_error(). " with query ". $query); mysql_query($query); mysql_close(); } if (isset($ud_update)){ added(); }?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/#findComment-147224 Share on other sites More sharing options...
dtyson2000 Posted December 24, 2006 Author Share Posted December 24, 2006 Maybe there's another approach altogether? After sleeping on it (and hoping there may be a response), I've come up with nothing. Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/#findComment-147285 Share on other sites More sharing options...
dtyson2000 Posted December 27, 2006 Author Share Posted December 27, 2006 Ok... so this is a shameless "bump" to see if anybody else might have an idea. I apologize if bumping is against the rules. I'm just at a total loss.Again, what is happening is that the record is edited with the result that the record with the old information is reloaded and followed by a display of the record with the new information. I just want the new information to replace the form above it altogether. Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/#findComment-148111 Share on other sites More sharing options...
fert Posted December 27, 2006 Share Posted December 27, 2006 to do that you need to use the sql UPDATE keyword Quote Link to comment https://forums.phpfreaks.com/topic/31748-edit-form-replace-with-new-information/#findComment-148113 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.