Jump to content

quick header issue


eric11

Recommended Posts

Hi, I'm having trouble with redirect my page to another page. what I have is a page that uses a form to insert into a database, the form is then processed to another page (insert.php) which will insert the information inserted in the form. I'm trying to work out how I could redirect the user to another page once the data has been successfully inserted.

 

this is what I have now:

insert.php

 

<?php
$link = mysql_connect('ericlee.dot5hostingmysql.com', 'user', 'password'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
//echo 'Connected successfully'; 

mysql_select_db('remarch', $link);

$sql="INSERT INTO posts (Name, Location, Fault, Other, Description)
VALUES
('$_POST[name]','$_POST[location]','$_POST[fault]','$_POST[other]','$_POST[description]')";
header('Location: about.html');

if (!mysql_query($sql,$link))
  {
  die('Error: ' . mysql_error());
  }

mysql_close($link);

?>

 

I'm pretty sure it's just the placing of the code

header('Location: about.html');
.

Would be appreciated if someone could give me some guidance :)

 

Thank you in advance!

Link to comment
Share on other sites

You never said what trouble you were having. I ran your script and the only thing I get is 'about.html' not found.

 

Is about.html in the same folder as this program? Does the program write to the screen? The only two thing that might cause the redirect to not work.

 

 

sorry, didn't clarify well. the error that comes up is

Warning: Cannot modify header information - headers already sent by (output started at /hermes/bosweb/web221/b2217/d5.ericlee/public_html/remarch/insert.php:10) in /hermes/bosweb/web221/b2217/d5.ericlee/public_html/remarch/insert.php on line 29
or whatever line the header is at.

 

the 'about.html' page is located in the same folder... i was able to solve almost the same issue in another script/page i have.. but for this page... it's not working.. ><"

the program does not write to the screen... simply, once the form is submitted... it will redirect to the about page automatically.

 

any other ideas?

 

thanks guys :)

Link to comment
Share on other sites

That error means that you have output on your screen on line 10.

You cannot send ANY information to a brower before a header() call.

Also adding exit() after a header() is a good idea as it helps prevent any other script execution.

Link to comment
Share on other sites

on line 10 its just a <?php

 

i tried putting up the header before that.. however.. similar errors still show up.

at the moment i have:

 

<body>
<?php header('Location: about.html'); ?>
<?php
$link = mysql_connect('.com', 'xxx', 'xxx'); 
if (!$link) { 
    die('Could not connect: ' . mysql_error()); 
} 
//echo 'Connected successfully'; 
mysql_select_db('remarch', $link);

$sql="INSERT INTO posts (Name, Location, Fault, Other, Description)
VALUES
('$_POST[name]','$_POST[location]','$_POST[fault]','$_POST[other]','$_POST[description]')";

if (!mysql_query($sql,$link))
  {
  die('Error: ' . mysql_error());
  }

mysql_close($link);
?>
</body>

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.