Jump to content
Larry Ullman's Book Forums

Escape_Data And $Dbc Trouble


Recommended Posts

In Chapter 13 the mysql_connect.php script.

 

I have all the information on this script that is in the book and the script from the supporting website. I have it on the page at the top.

 

I'm getting this error for each of my fields:

 

An error occurred in script '/hsphere/local/home/.../.../.../includes/mysqlconnect.php' on line 37: mysql_real_escape_string() expects parameter 2 to be resource, null given Array ( [data] => Dave [dbc] => )

 

This is line 37:

$data = mysql_real_escape_string (trim($data), $dbc);

 

The error page also has this:

An error occurred in script '/hsphere/local/home/.../.../.../into_register.php' on line 223: mysql_close(): supplied argument is not a valid MySQL-Link resource Array ( [GLOBALS] => Array *RECURSION* [HTTP_RAW_POST_DATA] => first_name=Dave&last_name=

This is line 223: "mysql_close($dbc); // Close the database connection."

 

 

My php version is 5.2.17

When I run phpinfo.php I see no listing for "mysql_real_escape_string", but "magic_quotes_gpc" is turned on.

 

Thanks

Dusty

Link to comment
Share on other sites

We need to see the code from the mysql_connect.php script which defines $dbc. Check for any typos as the smallest thing can cause an error e.g. you have named one file mysqlconnect.php and another into_register.php. Its important to be consistent with your naming conventions.

Link to comment
Share on other sites

I found the source of my problem... me.

 

I use a functions page for my websites that contains the header, footer and other code for my members area pages. I call it into a page through an include. This allows me to make additional pages quickly & easily and it cuts down on the amount of code/html I have to put on a page other than that which is specific to that individual page.

 

If works great, but in an effort to further minimze the information I put on my pages I put the require_once('includes/mysqlconnect.php'); on the functions page and appearantly this is what created my problem. When I removed the require_once from my functions page and put it back on the individual pages it worked fine.

 

My functions page is located in the members directory root while the mysqlconnect.php is located in the "includes" folder within the members directory. On my pages I call the functions page in with include('functions.php'); and inside that include was the require_once include for the connect script. I'm guessing that inlcudes in an include isn't a good thing.

 

Anyway, its working now. Sorry for the trouble and thanks for the response.

 

Dusty

  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...