Yuval200 Posted November 19, 2006 Share Posted November 19, 2006 Hey again guys :)I have a file named get.php that does all the header commands in my system, works great.Problem is, I use the file to do some MySQL commands too, so I must include a file with the connection details ect. Now, it works great too, but a week or so ago the file made the get page to die and print some headers and outpost errors.The thing I dont get is, when I copy all the commands from the included DB file to the get file and replace the include line with those commands, it all works great.I'm desperate :)Thanks,Yuval. Link to comment Share on other sites More sharing options...
CStrauss Posted November 19, 2006 Share Posted November 19, 2006 Hey again guys :)I have a file named get.php that does all the header commands in my system, works great.Problem is, I use the file to do some MySQL commands too, so I must include a file with the connection details ect. Now, it works great too, but a week or so ago the file made the get page to die and print some headers and outpost errors.The thing I dont get is, when I copy all the commands from the included DB file to the get file and replace the include line with those commands, it all works great.I'm desperate :)Thanks,Yuval.Can you post some code so we can see what is going on. From the sound of it, it seems your getting the classic header error in which case your outputting information after the header has already been displayed. if you can post your code or a similar example of your code we might be able to see whats going on. Link to comment Share on other sites More sharing options...
Yuval200 Posted November 20, 2006 Author Share Posted November 20, 2006 Can you post some code so we can see what is going on. From the sound of it, it seems your getting the classic header error in which case your outputting information after the header has already been displayed. if you can post your code or a similar example of your code we might be able to see whats going on.I know what error you're talking about, there is no "echo" things in the DB file. When I paste ALL the code from that file to the get.php file, it's ok, otherwise, header errors. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 20, 2006 Share Posted November 20, 2006 It's hard to say without seeing some code. Link to comment Share on other sites More sharing options...
Yuval200 Posted November 22, 2006 Author Share Posted November 22, 2006 It's hard to say without seeing some code.The code doesn't matter, because when I don't include the file, but add ALL it's content, it still works..Lets say that I have 1.php and 2.php, 1.php content is:x 2.php is: y When I include 1.php in 2.php, it gives headers errors, but when I copy all the code from 1.php to 2.php, like: xy It works perfectly..I you still don't get the errors, then I'll give the real codes for the files..Thanks. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 22, 2006 Share Posted November 22, 2006 The file include itself is not causing the error, something in the code is responsible. So the code definately matters. Link to comment Share on other sites More sharing options...
jlhaslip Posted November 23, 2006 Share Posted November 23, 2006 Supplying the code only matters if he wants to solve the issue. Link to comment Share on other sites More sharing options...
Yuval200 Posted November 28, 2006 Author Share Posted November 28, 2006 I'm really sorry for the late post Anyway, that's the code: <?php define(yp_mysql_connect , mysql_connect("localhost" ,"root")) ; define(yp_mysql_select_db , mysql_select_db("yuvpost", yp_mysql_connect)); $form_name = trim(mysql_real_escape_string($_POST["post_name"])) ; $form_content = trim(mysql_real_escape_string(nl2br(stripslashes($_POST["post_content"])))); $form_date = date('j/n/Y G:i') ;?> And I tested the file and clear all the content from it, and it worked great.. I'm insane! Link to comment Share on other sites More sharing options...
reportingsjr Posted November 28, 2006 Share Posted November 28, 2006 Whats with all the whitespace? That could be an issue with the define()s. When using $_POST or any of those I wouldn't recommend using double quotes, just single quotes . Link to comment Share on other sites More sharing options...
jesh Posted November 28, 2006 Share Posted November 28, 2006 I'm really sorry for the late post Anyway, that's the code:<?php define(yp_mysql_connect , mysql_connect("localhost" ,"root")) ; define(yp_mysql_select_db , mysql_select_db("yuvpost", yp_mysql_connect)); $form_name = trim(mysql_real_escape_string($_POST["post_name"])) ; $form_content = trim(mysql_real_escape_string(nl2br(stripslashes($_POST["post_content"])))); $form_date = date('j/n/Y G:i') ;?> And I tested the file and clear all the content from it, and it worked great.. I'm insane! Since I haven't touched PHP in a while I may be totally off-base here but according to the PHP manual, define is used to define constants (as opposed to variables/pointers/references). Maybe the problem is that you can't assign a database connection to a constant. If I'm totally wrong, just ignore this post. Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2006 Share Posted November 29, 2006 You are correct, sir. Only scalar data (boolean, integer, float and string) can be contained in constants. Do not define resource constants.The return value from mysql_connect is a resource, not a scalar type. Also, it doesn't make any sense to define a constant to be the return value of mysql_select_db, which returns true or false. So the value of the constant yp_mysql_select_db would be true or false.It doesn't really matter too much though, because you don't even need to save the return values from either mysql_connect or mysql_select_db. The only reason you would need to save the return value from mysql_connect is if you are connecting to multiple databases or database servers.Anyway, what's the problem again? You said you were including a file and it was causing a header error. Is this the file you are including? Because nothing in it would cause a header error, unless trying to define a constant resource is producing an error or a warning, which would not allow headers to be sent, but in that case I would think your question would be about the error message that is causing the headers to fail..Also, when you define a constant, the name goes in quotes. Not having the name in quotes causes a notice about an undefined constant. Link to comment Share on other sites More sharing options...
Yuval200 Posted November 29, 2006 Author Share Posted November 29, 2006 So if I got you guys right, you're saying that I can't put DB information in constants? That's interesting, because I once used a larger DB file that contained the following lines and more, and it did worked.So, you're talking about notice errors and all that stuff, can I please just have a list of all the things I need to fix? My English skills are not that strong as you might know..And yes, the error I'm getting is that "Headers allready sent" thing.Thanks guys Link to comment Share on other sites More sharing options...
justsomeguy Posted November 29, 2006 Share Posted November 29, 2006 You can't store a resource, which includes a database connection, in a constant. You can only store "scalar" or "atomic" values, which are things like numbers, words, true/false, etc. If you think about it, it makes sense because a constant, by definition, does not change. When you connect to a database to get a recordset back, that recordset may change.You can put your connection information in constants, because they are just words. You can have a constant for the database host, user, password, etc, but not the actual connection.You can replace your two define lines with just this and it will do the same thing:mysql_connect("localhost" ,"root");mysql_select_db("yuvpost");As far as the header errors, there is nothing in the code you posted that would cause it (other then possibly having an invalid connection given to the mysql_select_db function). The reason has to be somewhere else. Link to comment Share on other sites More sharing options...
Yuval200 Posted November 30, 2006 Author Share Posted November 30, 2006 "As far as the header errors, there is nothing in the code you posted that would cause it (other then possibly having an invalid connection given to the mysql_select_db function). The reason has to be somewhere else."As I fought, thanks :)Then PHP just hates me, that's logical..Thanks for the tips anyway.. I'll just put the DB info in a data file and again in the get file..Again, Thanks alot for all the help guys Link to comment Share on other sites More sharing options...
justsomeguy Posted November 30, 2006 Share Posted November 30, 2006 Well, computers don't do things for no reason. They only do what they are specifically told to do, so there is an unambiguous reason why this is happening. But the reason is not in the code you posted. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now