Page 1 of 1

Action page called from a form forced to be a download file

Posted: Mon Oct 23, 2006 2:12 pm
by juliaw
hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I am new to php and am stumbling at almost the first block! I have searched around for this problem in google and this forum but I don't see a similar problem.

I have two simple pages, one a form and the second the action page with php in it.  I have actually copied the code from an example.
When i go into the form, enter the data and click on submit, my computer is treating it as a download file and comes up with the 'File download - security warning' popup.

my pages are:

Code: Select all

<html>
<head>
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method="post" action="do_addtopic.php">
<p><strong>Your E-Mail Address:</strong><br/>
<input type="text" name="topic_owner" size="40" maxlength="150"/></p>
<p><strong>Topic Title:</strong><br/>
<input type="text" name="topic_title" size="40" maxlength="150"/></p>
<p><strong>Post Text:</strong><br/>
<textarea name="post_text" rows="8" cols="40" wrap="virtual"></textarea></p>
<p><input type="submit" name="submit" value="Add Topic"></p>
</form>
</body>
</html>

do_addtopic.php page follows

Code: Select all

<?php
//check for required fields from the form
if ((!$_POST["topic_owner"]) || (!$_POST["topic_title"]) || (!$_POST["post_text"])) {
	header("Location: addtopic.html");
	exit;
}

//connect to server
$mysqli = mysqli_connect("localhost", "xxxx", "yyyy", "zzzz");

//create and issue the first query
$add_topic_sql = "INSERT INTO forum_topics (topic_title, topic_create_time,topic_owner) VALUES ('".$_POST["topic_title"]."',now(), '".$_POST["topic_owner"]."')";
$add_topic_res = mysqli_query($mysqli, $add_topic_sql) or die(mysqli_error($mysqli));

//get the id of the last query
$topic_id = mysqli_insert_id($mysqli);

//create and issue the second query
$add_post_sql = "INSERT INTO forum_posts (topic_id,post_text,post_create_time,post_owner) VALUES ('".$topic_id."', '".$_POST["post_text"]."', now(), '".$_POST["topic_owner"]."')";
$add_post_res = mysqli_query($mysqli, $add_post_sql) or die(mysqli_error($mysqli));

//close connection to MySQL
mysqli_close($mysqli);

//create nice message for user
$display_block = "<P>The <strong>".$_POST["topic_title"]."</strong> topic has been created.</p>";
?>
<html>
<head>
<title>New Topic Added</title>
</head>
<body>
<h1>New Topic Added</h1>
<?php echo $display_block; ?>
</body>
</html>
Any help would be gratefully received,

Thank you in anticipation

Julia


hawleyjr | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

Posted: Mon Oct 23, 2006 3:16 pm
by amir
I think your code is OK. May be you have not placed your code file in proper place. Can you tell me where you have it? Because it is must that you place it in your web server directory that may be www, htdocs etc.

Posted: Mon Oct 23, 2006 4:02 pm
by s.dot
It doesn't sound to me like you are running a PHP enabled web server, or your apache configuration is not configured to recognize PHP.

Posted: Mon Oct 23, 2006 5:16 pm
by RobertGonzalez
Exactly. your web server does not know what to do with .php files. What server are you running?