General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old May 5th, 2003, 02:22 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
what's wrong with this?

I know the mistake is about the headers and cookies but how do I fix this? I want to login the user here and collect the cookies so that on the next page I can refer to the user by name and also use cookies to check the database and see if they have voted. If you need to see more of my code I can include that next time.
Also, instead of using echo, I plan to use includes. Is that a problem?
I know my name is popping up a lot on this forum so I apologise for being a pain - but I really need the help.
<?
include 'configuration.php';

$username=$HTTP_POST_VARS['username'];
$password=$HTTP_POST_VARS['password'];

if ((!$username)||(!$password))
{
echo 'no filled in';
exit;
}
else
{
$db = mysql_connect("$dbhostname","$dbuser","$dbpass") or die ("error connecting to database.");
mysql_select_db("$dbdatabase",$db) or die ("could not select the databse");
$sql_login_check = mysql_query("SELECT * FROM user WHERE username='$username' AND password= '$password'") or die ("$query_username". mysql_error());

if (mysql_num_rows($sql_login_check) == 0)
{
echo 'you are not';
exit;
}
else
{
while ($users_array = mysql_fetch_array($sql_login_check))
{
//
$first_name = $users_array['first_name'];
$second_name = $users_array['second_name'];
$username = $users_array['username'];
$email = $users_array['email'];
$vote_completed = $users_array['vote_completed'];

setcookie("first_name", "$first_name");
setcookie("second_name", "$second_name");
setcookie("username", "$username");
setcookie("email", "$email");
setcookie("vote_completed", "$vote_completed");
}

include('place_vote.php');
}
}
?>

Reply With Quote
  #2  
Old May 5th, 2003, 03:37 PM
RiC]-[iE RiC]-[iE is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Sweden
Posts: 6 RiC]-[iE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Make sure that there are no spaces or html before <?php. If there is, then the setcookie() and header() functions will give you this error.

Reply With Quote
  #3  
Old May 5th, 2003, 05:47 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
hey...

dont worry about your name popping up on the forums!! its always good to hear from other programmers, and because of sites like this we can all learn from each other!! .... we all started somewhere!!

... just one pointer though.... the rules on the forums ask you to be descriptive in naming the title of a new post... you will get more people reading a post such as "PHP cookie problems" rather than "I need help with this..." -- just a thought!! hehe!

if you want to use includes instead of echo's there is no problem there! At least I dont think there would be!

btw...what is the exact error message your getting? I couldnt find it in your post!
__________________
Matt 'Fakker' Facer

mattfacer.com

Reply With Quote
  #4  
Old May 5th, 2003, 06:25 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
nope, no peasky gaps.
how can I initialise the cookies on this page without getting "header" errors? I think it should be at the top but I'm guessing.
Craig.

Reply With Quote
  #5  
Old May 5th, 2003, 06:27 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
yeah, the cookies need to be set before anything is outputted to the browser...... so they should really be at the top of the page....

Reply With Quote
  #6  
Old May 5th, 2003, 06:32 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
error message with php and cookies

Here it is - and it's on the screen for every line where I try and set a cookie (so 5 times)

Warning: Cannot add header information - headers already sent by (output started at c:\phpdev\www\safeish\configuration.php:3) in c:\phpdev\www\safeish\login_validation.php on line 33

Reply With Quote
  #7  
Old May 5th, 2003, 06:34 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
could you post that code? the configuration part?

Reply With Quote
  #8  
Old May 5th, 2003, 06:35 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
setting cookies

how exactly do i do that? what from this code do i need to chop and change? (or should I just do a complete overhaul?)

$first_name = $users_array['first_name'];
$second_name = $users_array['second_name'];
$username = $users_array['username'];
$email = $users_array['email'];
$vote_completed = $users_array['vote_completed'];

setcookie("first_name", "$first_name");
setcookie("second_name", "$second_name");
setcookie("username", "$username");
setcookie("email", "$email");
setcookie("vote_completed", "$vote_completed");

Thanks for you help.

Reply With Quote
  #9  
Old May 5th, 2003, 06:38 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
configuration code

first I use this at the top of every page:
include 'configuration.php';

but it takes its info from this:
<?
$dbhostname = "localhost";
$dbuser = "root";
$dbpass = "";
$dbdatabase = "awsd";
?>

Reply With Quote
  #10  
Old May 5th, 2003, 06:40 PM
fakker fakker is offline
The calm b4 the storm
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2002
Location: Manchester, UK
Posts: 404 fakker User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via Yahoo to fakker
ok.... what is line 33 in the file "c:\phpdev\www\safeish\login_validation.php" ??

Reply With Quote
  #11  
Old May 5th, 2003, 06:44 PM
jpenn jpenn is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Oct 2002
Location: Washington, DC
Posts: 317 jpenn User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 m 3 sec
Reputation Power: 6
Use the output buffer ->
PHP Code:
/**************************************
Put at very first line in script before anything
**************************************/
ob_start();
/**************************************
Do all your code crap, session stuff, etc
**************************************/ 
__________________
~ Joe Penn

We work for free to help make this a valuable resource on the internet. Do you appreciate the help - did we provide help that will help you prosper and help that has contributed to sharpening your current skill set?

Show your appreciation and purchase something from our Amazon Wishlist's - it's simple and a great way to say thank you.




Reply With Quote
  #12  
Old May 5th, 2003, 06:44 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
these lines are what give me errors and I'm sure its cos they're in the wrong place but if I don't know how to just move them to the top.

32 setcookie("first_name", "$first_name");
33 setcookie("second_name", "$second_name");
34 setcookie("username", "$username");
35 setcookie("email", "$email");
36 setcookie("vote_completed", "$vote_completed");

Reply With Quote
  #13  
Old May 5th, 2003, 06:47 PM
craigtaylor74 craigtaylor74 is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: May 2003
Posts: 13 craigtaylor74 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I don't know how to use sessions and to be honest time is not on my side. it's a tutorial project I need to hand in in the morning (UK time). if I can't figure out these pesky cookies I may just call it a day and leave sessions for another time.

Reply With Quote
  #14  
Old May 6th, 2003, 12:19 AM
RiC]-[iE RiC]-[iE is offline
Junior Member
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Sweden
Posts: 6 RiC]-[iE User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'll say this again. Make sure that there are no spaces before <?php in the beginning of the file. This will give you this error. If there is some html code there, then this will give you an error too.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > what's wrong with this?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support |