Forum Moderators: coopster

Message Too Old, No Replies

jump to html page from php

jump to html page from php

         

wsenter

5:56 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



I am a php newbe and I am trying to figure out how to simply display an existing html page from my php script. Here is the code I use but I get the normal "output started" errors.

$sql = "INSERT INTO author SET
firstname='$name1',
lastname='$name2',
workphone='$workphone',
email='$email',
loginid='$loginid',
password='$password'";
if (@mysql_query($sql)) {
header("Location: formSubmit.htm"); <--------HERE

I would appreciate any help I can get.

thanks

jatar_k

6:01 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld wsenter,

There can be no output to the browser before certain functions, like header. Even a blank line before your <?php can cause this error as that blank line will be output to the browser.

wsenter

6:28 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Thanks for the quick reply. Can you suggest an alternative. Here is what I am trying to do.

I have a form inside an .html file that collects data from user. The form tag calls the .php file that you see part of in this thread and passes all variable data to it for posting to mySQL database. At the bottom of php code (shown) there is the if , else. If the post is successful, I simply wanted to dispay another formatted .html file that says the users data was accepted ok and displays the data entered for review. Otherwise dislay an error in a different .html page.

Thanks again..

ergophobe

9:29 pm on Jan 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Relatively simple. In principle, you must delay output until the very end of execution. I think this is good practice for a variety of reasons. You can take two approaches.

1. use output buffering [us3.php.net]

2. handle it programmatically. To do that, you basically just assign your output to a variable or set of variables. So instead of

echo "The first thing I want to say";
echo "The second thing I want to say";

you use

$content = ""; // first we initialize our variable

...

$content .= "The first thing I want to say";
$content .= "The second thing I want to say";

Then, at the end of the script

echo $content;

Either way will work as will both together.

wsenter

11:45 pm on Jan 6, 2005 (gmt 0)

10+ Year Member



Can some look at the code for this .php page and tell me why everything between the <?php tags does not display when executed? Namely , the form.

[SNIP html header]

<?php if (isset($_GET['lastname'])):?>

<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<table border="0" cellspacing="6" cellpadding="0">
<tr><td>First Name</td></tr>

[SNIP many similar rows]

<tr><td><input type="submit" name="Submit" value="Send">
<input type="reset" name="Submit2" value="Reset Form"></td></tr>
</table>
</form>

<?php else:

$dbcnx = @mysql_connect('localhost', 'codemake_codemak', '$code$');
If (!$dbcnx) {
exit('<p>Unable to connect to the ' .
'database server at this time.</p>');
}

If (!@mysql_select_db('codemake_helpdesk')) {
exit('<p>Unable to locate the Helpdesk ' .
'database at this time.</p>');
}

if (isset($_POST['lastname'])) {

$name1 = $_POST['firstname'];
$name2 = $_POST['lastname'];
$workphone = $_POST['workphone'];
$email = $_POST['email'];
$loginid = $_POST['loginid'];
$password = $_POST['password'];
$sql = "INSERT INTO author SET
firstname='$name1',
lastname='$name2',
workphone='$workphone',
email='$email',
loginid='$loginid',
password='$password'";

if (@mysql_query($sql)) {
echo '<p>New Author Added</p>';

} else {

echo '<p>Error adding new author: ' .
mysql_error() . '</p>';
}
}

endif;
?>

<p class="copyrights">Lorem ipsum dolor

[SNIP - lots of text]
</p>

[edited by: ergophobe at 12:15 am (utc) on Jan. 7, 2005]
[edit reason] code dump snipped - please read forum charter [/edit]