Drupal, Bad Block PHP & Broken Site!

in

Q: I was changing some PHP code in one of my blocks, saved it, and now my website won't display at all - how can I fix the problem?
A: This is a real pain, but to get around the problem you can update your drupal database directly to switch off the block, your website should then work again and you can fix the PHP error.

Sometimes if you save a block that contains a PHP error, your drupal website may no longer display at all, and you can't easily undo the error or switch off the block as you can't access the admin pages - very worrying stuff!

To get the site up again you need to switch off the offending block, this can be done by manually updating the drupal databse.

NB Before messing around with your database make sure to back-it-up first as it is very easy to make a mistake and do real damage to your website!!

To switch off the bad block, first Launch phpMyAdmin and browse the 'blocks' table, you should see a list of all your blocks. Have a look for the offending one, you should be able to spot it by its title or other distinguising attribute. Once you find it take a not of its 'bid', this is its unique identifier and is the first column of the 'blocks' table, let's call this offending_bid.

Now, from phpMyAdmin execute the follwoing SQL:

UPDATE blocks SET region='',status=0 WHERE bid=offending_bid

Remember to replace 'offending_bid' with the bid of your bad block.

This SQL, once executed, will switch off the block and your site should be operational again - now you can fix the block!!

To prevent this from happening again it's always a good idea to have your block only display on a test page when you're developing it. To do this, modify its settings so that in the 'Show block on specific pages: ' section the option 'Show on only the listed pages.' is selected and provide the path to the test page in the box below. Now if an error creeps in again it will only affect this page!

This happened to me (again) last night, and it's not a nice feeling at all, so I hope that this post helps someone in a similar fix!

Joined: 10/10/2008
User offline. Last seen 1 week 3 days ago.
Sounds like you might have

Sounds like you might have found that out the hard way KEV???

-----------------------------------------------

Award Winning Web Design Cork : Pride Web Design Cork

-----------------------------------------------

Joined: 08/01/2009
User offline. Last seen 3 weeks 4 days ago.
To my shame I have found it

To my shame I have found it the hard way more than once, always when I'm in a hurry and makin a 'little change' ;-)

Stranger
Stranger's picture
I found another way...

Today I saved a PHP error into a block and broke my site. Luckily I had an administrative theme set up which did not contain the offending block. I could use my history to view admin pages, but couldn't load any pages which used my default theme, including the Blocks admin page.

This was the only page I found while looking for a solution. Rather than going into the database (which I don't have access to, and was a bit nervous about messing with) this is what I did:

  • I opened my theme's .info file and removed the region which the offending block was in.
  • I cleared the cache, and the rest of the site came back!
  • I was then able view the Blocks admin page, and remove the offending block.
  • Finally, I added the region back to my .info file, reposted it, cleared the cache, and am back in business!
Next time I'll follow your advice and only display my PHP blocks on a test page until I have them working correctly.

Joined: 10/10/2008
User offline. Last seen 1 week 3 days ago.
i'd say you were in a bit of

i'd say you were in a bit of a panic finding that solution!!!

-----------------------------------------------

Award Winning Web Design Cork : Pride Web Design Cork

-----------------------------------------------

Stranger
Stranger's picture
(No subject)

Joined: 10/10/2008
User offline. Last seen 1 week 3 days ago.
ha ha

easier said then done! ... thanks for sharing the tip though, might come in very useful one day!

-----------------------------------------------

Award Winning Web Design Cork : Pride Web Design Cork

-----------------------------------------------

Stranger
Stranger's picture
thanks!

thanks man!

Joined: 03/05/2010
User offline. Last seen 1 year 36 weeks ago.
Thanks for sharing this post.

Thanks for sharing this post. This is a very helpful and informative material. Good post and keep it up.

_____________________________________________________________
Daniel Perl

Stranger
Stranger's picture
Thanks for sharing this, but

Hi,

Thanks for idea, but I had same problem with Drupal5 and if you follow that procedure - you will probably get an error message: "You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column", that`s because D5 has no keys for this table;
you can sort it out something like this;

"UPDATE `blocks` set `region`='', `status`=0 where `region`='left' and `delta`=1 limit 2;"

- add limit at the end too always, - inspired by MySQL Docs.
http://dev.mysql.com/doc/refman/5.0/en/update.html

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Pride on FacebookPride on TwitterPride on TwitterPride on Twitter

Join Our Newsletter

* indicates required

Irish Internet Association

finalist.png
phone-number.png