Jump to content

edit form replace with new information


dtyson2000

Recommended Posts

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?
Link to comment
Share on other sites

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]
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.