php problem with form action and build a forum

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
az26
Forum Newbie
Posts: 2
Joined: Thu Aug 11, 2016 6:17 am

php problem with form action and build a forum

Post by az26 »

Hello,
I'm beginner in php and I'm trying to build a forum in website.
I build form action and when user press submit it will go to "add_new_topic.php" file and then insert the data to db.
but when I do that it takes my to the index.php and logout from user.
I checked everything and also put attention that I wrote session_start() in each page to remmeber the username
but I didn't get any solution to the problem.

here the 'newtopic.php' ---> I wrote there where is exactly the problem with the form
http://pastebin.com/QRztHjyR

here the 'add_new_topic.php'
http://pastebin.com/hE5WVaH8


thank for help.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php problem with form action and build a forum

Post by Celauran »

http://php.net/manual/en/function.session-start.php
Note:
To use cookie-based sessions, session_start() must be called before outputing anything to the browser.
az26
Forum Newbie
Posts: 2
Joined: Thu Aug 11, 2016 6:17 am

Re: php problem with form action and build a forum

Post by az26 »

hey celauran,
thank you for you reply.
as you see I used session_start in all my php files and still has the problem.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: php problem with form action and build a forum

Post by Celauran »

Did you read the note above?
session_start() must be called before outputing anything to the browser
You are clearly sending output to the browser before calling session_start().
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: php problem with form action and build a forum

Post by Christopher »

newtopic.php is sending text to the browser before session_start() is called:

////***** newtopic.php *****/////
<link href="style_forum.css" rel="stylesheet" type="text/css">

<?php
$page = 1;$sub = 1;
session_start();
(#10850)
Post Reply