Page 1 of 1

php problem with form action and build a forum

Posted: Thu Aug 11, 2016 6:20 am
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.

Re: php problem with form action and build a forum

Posted: Thu Aug 11, 2016 7:04 am
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.

Re: php problem with form action and build a forum

Posted: Thu Aug 11, 2016 7:15 am
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.

Re: php problem with form action and build a forum

Posted: Thu Aug 11, 2016 8:26 am
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().

Re: php problem with form action and build a forum

Posted: Thu Aug 11, 2016 3:34 pm
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();