Jump to content

header . ('Location: . '); Gives an error


Recommended Posts

I have an administrator's page set up to update table contents in my database. It displays each field in a form using a table. Whenever I click on the submit button, I have to refresh the page to see the changes. But I want the changes to display immediately after clicking the submit button. I added header('Location: . ');exit(); to the code but I get the following error Warning: Cannot modify header information - headers already sent by (output started at /home/conservf/public_html/admin/edit_family.php:25) in /home/conservf/public_html/admin/edit_family.php on line 101 Below is the code - How can I fix this so when I edit the information in the table, it displays immediately? <body><div id="wrapper1"><a name="Top"></a><h1>Edit Family Names</h1><div class="textbox"><h4>Today is -<?php$my_t=getdate(date("U"));print("$my_t[weekday], $my_t[month] $my_t[mday], $my_t[year]<br />");?></h4><p><a href="<?php echo $_SERVER['PHP_SELF']; ?>?logout=1" >Logout</a></p><p><a href="http://www.conservfirst.com/admin/">Return to Admin Page</a></p><p><a href="edit_family.php">Refresh page</a></p><h4><a href="?addfamily">Add a new family</a></h4><?phpif (isset($_GET['addfamily'])){ include '/home/conservf/public_html/includes/addfamilyform.inc.html.php'; exit(); } ?></div><?php include '/home/conservf/public_html/includes/connection.inc.html.php'; ?><?php include '/home/conservf/public_html/includes/magicq.inc.html.php'; ?><?php include '/home/conservf/public_html/includes/helpers.inc.html.php'; ?><?php$sql = "SELECT * FROM family1 ORDER BY family_name"; $result = @mysql_query($sql); if (!result) { $error = 'Error fetching information'; exit();} echo '<table class="building"><tr><caption>Edit Family Names</caption</tr><tr><th>FAMILY</th><th>CATEGORY</th><th>DESCRIPTION</th><th>Item<br />order</th><th>In-<br />active</th></tr>'; while ($row = mysql_fetch_array($result)) { echo '<form action="http://www.conservfirst.com/admin/edit_family.php" method="post">';echo '<input type="hidden" name="familyid" value = "' . $row['familyid'] . '" />';echo '<td><input type="text" name="family_name" value = "' . htmlspecialchars($row['family_name'], ENT_QUOTES, 'UTF-8') . '" size="15" /></td>';echo '<td><input type="text" name="category" value = "' . htmlspecialchars($row['category'], ENT_QUOTES, 'UTF-8') . '" size="25" /></td>'; echo '<td><input type="text" name = "familydescription" value ="' . htmlspecialchars($row['familydescription'], ENT_QUOTES, 'UTF-8') . '" size="80" /></td>'; echo '<td><input type="text" name="item_order" value = "' . htmlspecialchars($row['item_order'], ENT_QUOTES, 'UTF-8') . '" size="2" /></td>'; echo '<td><input type="text" name="inactive" value = "' . htmlspecialchars($row['inactive'], ENT_QUOTES, 'UTF-8') . '" size="2" /></td>'; echo '<td><input type="submit" name="action" value="Edit" /></td></tr>'; if (isset($_POST['familyid'])) $familyid = $_POST['familyid']; $family_name = mysql_real_escape_string($_POST['family_name']); $category = mysql_real_escape_string($_POST['category']);$familydescription = mysql_real_escape_string($_POST['familydescription']); $inactive = $_POST['inactive']; $item_order = $_POST['item_order']; $sql = "UPDATE family1 SET family_name = '$family_name', category = '$category', familydescription = '$familydescription', inactive = '$inactive', item_order = '$item_order' WHERE familyid ='$familyid'"; if (!@mysql_query($sql)) { echo '<p>Error updating family1: ' . mysql_error() . '</p>'; exit(); } header('Location: . '); exit(); echo '</form>'; }echo '</table>';?></body>

Link to post
Share on other sites

you're trying to send hearder too late in the game, as it were.http://w3schools.inv...50 If you want a page to update without a refresh, you can either use AJAX, or just have a page submit to itself, which when done correctly, will give the same effect.

Edited by thescientist
Link to post
Share on other sites

I added: echo '<form action="' . $_SERVER['PHP_SELF'] . '" method="post">'; but it still doesn't show the changes until I refresh the page. I've also changed the form action to "http://www.conservfirst.com/admin/edit_family.php" but the changes still don't show up until I refresh the page. Any other suggestions?

Edited by lauralee
Link to post
Share on other sites

But the form fields are populated with the text from the database table that are to be edited, they are not empty fields where text is to be entered, so I can't do an UPDATE until after the form is displayed with the populated fields can I?

Link to post
Share on other sites

I don't know what you mean. From what I see, you SELECT and UPDATE from the same table. If you always want to SELECT and show the latest information, then you should UPDATE the table first with whatever information you are getting if a form was submitted.

Edited by thescientist
Link to post
Share on other sites

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.   Paste as plain text instead

  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.

Loading...
×
×
  • Create New...