smart Posted July 4, 2012 Share Posted July 4, 2012 when i use this CODE$content = $_POST['content'];it's working and inserting data in database but when i useWHEN i use$content = mysql_real_escape_string($_POST['content']); how i can solve this problem ?. Link to comment Share on other sites More sharing options...
birbal Posted July 4, 2012 Share Posted July 4, 2012 (edited) do you have DB conection made before you use mysql_real_escape_string() ? it takes DB conection as second parameter, if not specified it takes last open connection but in any case it needs the connection. It sounds like you have not made the connection prior to that. there is no way we can be totaly sure without seeing the code. Edited July 4, 2012 by birbal Link to comment Share on other sites More sharing options...
smart Posted July 4, 2012 Author Share Posted July 4, 2012 Yes i have made the connection but i have included connection.php like this in require("adminheader.php"); Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 4, 2012 Share Posted July 4, 2012 Yes i have made the connection but i have included connection.php like this in require("adminheader.php"); did u test the db connection? bye opening it into the browser? if you get a blank page its connected if you get a error means your not connected Link to comment Share on other sites More sharing options...
smart Posted July 4, 2012 Author Share Posted July 4, 2012 when i connect the database connection file like this require("adminheader.php") it's not working but when i write php code in the same pagemysql_connect("localhost","root","") or die ("could not connect to mysql");mysql_select_db("cabinatecart") or die ("no database"); above the file then it works.why Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 4, 2012 Share Posted July 4, 2012 is your adminheader.php in another file?, mhmm try checking to see if your query is working, that might be a problem also Link to comment Share on other sites More sharing options...
smart Posted July 4, 2012 Author Share Posted July 4, 2012 In my index.php i have included adminheader.php and in adminheader.php page i have included my connection.php file it's not working i can fetch the data in my index.php pageBut when i use mysql_real_escape_string() it's now working. Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 4, 2012 Share Posted July 4, 2012 In my index.php i have included adminheader.php and in adminheader.php page i have included my connection.php file it's not working i can fetch the data in my index.php pageBut when i use mysql_real_escape_string() it's now working. that is where you problem is, you need to include the connection.php into the current page your working on, if you have it included in another file then include that file into another file, it wouldnt work but if you take the connection.php and include it directly into the current page your working on it would work perfectly fine, try that, try taking the connection.php and place it into the .php file where the mysql_real_escape_string(); is located. Link to comment Share on other sites More sharing options...
birbal Posted July 4, 2012 Share Posted July 4, 2012 (edited) that is where you problem is, you need to include the connection.php into the current page your working on, if you have it included in another file then include that file into another file, it wouldnt work but if you take the connection.php and include it directly into the current page your working on it would work perfectly finethat is not true. include file will also work like that but it have to make sure that connection is made first before using mysql_real_escape_string(). include files will be included in the order they are declared. |=index.php |= includeparent.php | |= includechild.php | |= includechildanother.php |= config.php |= connection.php call will be index>includeparent>includechild>includechildanother>config>connection so at any point includeparent.php try to use mysql_real_escape_string() it will not be succed cause connection is made later in the stack in connection.php But when i use mysql_real_escape_string() it's now working.Where does you use that? post your code where you used it and the code where you made the connection. and what does mysql_real_escape_string() is returning? you can use var_dump() on its return value to see that Edited July 4, 2012 by birbal Link to comment Share on other sites More sharing options...
divinedesigns1 Posted July 5, 2012 Share Posted July 5, 2012 that is not true. include file will also work like that but it have to make sure that connection is made first before using mysql_real_escape_string(). include files will be included in the order they are declared. |=index.php |= includeparent.php | |= includechild.php | |= includechildanother.php |= config.php |= connection.php that's something new to me, thanks for the information birbal 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