Jump to content

Successful Update Throws Error?!


doubledee

Recommended Posts

Kicken, you still missed what I said above...

 

No, your not understanding what I am saying.

 

 

But back in "article.php" - after the require to "last_activity.php" I have...

// Connect to the database.
require_once(WEB_ROOT . 'private/mysqli_connect.php');

 

Yes, you have that.  But

 

That file is NOT included

The code in that file is NOT run

Therefore, you do NOT re-connect

 

You could just delete that line from your script, it would function the exact same way.

 

Link to comment
Share on other sites

That isn't what I said...

 

I said that at the top of "article.php" I require "last_activity.php"...

// Update Last Activity.
require_once('../members/last_activity.php');

 

 

And that "last_activity.php" opens and closes a database connection like this...

	// Connect to the database.
	require_once(WEB_ROOT . 'private/mysqli_connect.php');


	// Close prepared statement.
	mysqli_stmt_close($stmt);

	// Close the connection.
	mysqli_close($dbc);

 

But back in "article.php" - after the require - I have...

	// Connect to the database.
	require_once(WEB_ROOT . 'private/mysqli_connect.php');

 

So that should take care of my required file opening and closing the connection, right?!

 

When you require_once something, it does exactly that: requires it once. Any subsequent attempts to include the file fail, because you said you only want to do that once. So you are essentially doing:

require_once(WEB_ROOT . 'private/mysqli_connect.php');

... more code ...

require_once(WEB_ROOT . 'private/mysqli_connect.php');

 

Therefore, the second one won't work.

 

The easiest thing to do here is to just connect to the database earlier than last_activity and don't worry about closing it.

Link to comment
Share on other sites

When you require_once something, it does exactly that: requires it once. Any subsequent attempts to include the file fail, because you said you only want to do that once. So you are essentially doing:

require_once(WEB_ROOT . 'private/mysqli_connect.php');

... more code ...

require_once(WEB_ROOT . 'private/mysqli_connect.php');

 

Therefore, the second one won't work.

 

The easiest thing to do here is to just connect to the database earlier than last_activity and don't worry about closing it.

 

My bad!  I see where I wasn't getting things.

 

See, that is why you are a guru and I'm just a newb...  :-[

 

BTW, if I didn't have require_once and instead had require does it hurt things if I connect to me database more than once?

 

I'm sorta debating where to put my Connection String, because if I just had it "last_activity.php" then some of my parent scripts might fail because they need it too, but if I just put it in the parent scripts but there is a time where I require "last_activity.php" and the aprent script doesn't have a Connection String then "last_activity.php" should have it.

 

I suppose I just need to think things out and have a better strategy?!

 

 

Debbie

 

Link to comment
Share on other sites

BTW, if I didn't have require_once and instead had require does it hurt things if I connect to me database more than once?

 

It means you will be connecting to the database more than once, which doesn't make any sense. You are just wasting server resources.

 

I'm sorta debating where to put my Connection String, because if I just had it "last_activity.php" then some of my parent scripts might fail because they need it too, but if I just put it in the parent scripts but there is a time where I require "last_activity.php" and the aprent script doesn't have a Connection String then "last_activity.php" should have it.

 

I suppose I just need to think things out and have a better strategy?!

 

Connect to the database before anything else, and then you don't have to worry about it.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.