|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
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'); } } ?> |
|
#2
|
|||
|
|||
|
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.
|
|
#3
|
|||
|
|||
|
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! |
|
#4
|
|||
|
|||
|
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. |
|
#5
|
|||
|
|||
|
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....
|
|
#6
|
|||
|
|||
|
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 |
|
#7
|
|||
|
|||
|
could you post that code? the configuration part?
|
|
#8
|
|||
|
|||
|
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. |
|
#9
|
|||
|
|||
|
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"; ?> |
|
#10
|
|||
|
|||
|
ok.... what is line 33 in the file "c:\phpdev\www\safeish\login_validation.php" ??
|
|
#11
|
|||
|
|||
|
Use the output buffer ->
PHP Code:
__________________
~ 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. |
|
#12
|
|||
|
|||
|
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"); |
|
#13
|
|||
|
|||
|
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.
|
|
#14
|
|||
|
|||
|
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.
|
![]() |
| Viewing: Dev Articles Community Forums > Programming > General Programming Help > what's wrong with this? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|