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
https://forums.phpfreaks.com/topic/248685-quick-header-issue/
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.

 

Link to comment
https://forums.phpfreaks.com/topic/248685-quick-header-issue/#findComment-1277194
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
https://forums.phpfreaks.com/topic/248685-quick-header-issue/#findComment-1277384
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
https://forums.phpfreaks.com/topic/248685-quick-header-issue/#findComment-1277391
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.