Showing posts with label Web Programming. Show all posts
Showing posts with label Web Programming. Show all posts

Monday, October 19, 2009

Getting Rid of the "Access denied for user ..." Error in PHP

This error usually looks like this :
Warning: mysql_query() [function.mysql-query]: Access denied for user 'ODBC'@'localhost' (using password: NO) in C:\xampp\htdocs\intra\process_mypage.php on line 382

Warning: mysql_query() [function.mysql-query]: A link to the server could not be established in C:\xampp\htdocs\intra\process_mypage.php on line 382

To get rid of this error, follow this step :
  • Check your connection to the database
  • Check server name, username and password
  • Check whether the connection is opened or not, because the common mistake is that you forgot to open the connection :p

Monday, July 13, 2009

53 CSS-Techniques You Couldn’t Live Without

CSS is important. And it is being used more and more often. Cascading Style Sheets offer many advantages you don’t have in table-layouts - and first of all a strict separation between layout, or design of the page, and the information, presented on the page. Thus the design of pages can be easily changed, just replacing a css-file with another one. Isn’t it great? Well, actually, it is.

Over the last few years web-developers have written many articles about CSS and developed many useful techniques, which can save you a lot of time - of course, if you are able to find them in time. Below you’ll find a list of techniques we , as web-architects, really couldn’t live without. They are essential and they indeed make our life easier. Let’s take a look at 53 CSS-based techniques you should always have ready to hand if you develop web-sites. Links checked: June/11 2008.

[Smashing Magazine]

Tuesday, June 16, 2009

Getting Rid of the Headers Already Sent Error in PHP

The "Headers Already Sent" error is incredibly common, usually looks like this :
Warning: Cannot modify header information - headers already sent by (output started at /home/myaccount/public_html/globals.php:42) in /home/myaccount/public_html/index.php on line 198

To get rid of this, you can try one of the following tips :
  • replace the header('location:page.php') with <script>window.location='page.php'</script>
  • remove all blank spaces before the phrase header('location:page.php')
    Blank spaces includes html tags, press of enter, or just a single press of spacebar.
  • remove all white space before or after the opening and closing PHP tags.

Friday, May 29, 2009

Text Flipper Script

<script language="JavaScript">
function flip() {
var result = flipString(document.f.original.value.toLowerCase());
document.f.flipped.value = result;
}

function flipString(aString) {
var last = aString.length - 1;
//Thanks to Brook Monroe for the
//suggestion to use Array.join
var result = new Array(aString.length)
for (var i = last; i >= 0; --i) {
var c = aString.charAt(i)
var r = flipTable[c]
result[last - i] = r != undefined ? r : c
}
return result.join('')
}

var flipTable = {
a : '\u0250',
b : 'q',
c : '\u0254', //open o -- from pne
d : 'p',
e : '\u01DD',
f : '\u025F', //from pne
g : '\u0183',
h : '\u0265',
i : '\u0131', //from pne
j : '\u027E',
k : '\u029E',
//l : '\u0283',
m : '\u026F',
n : 'u',
r : '\u0279',
t : '\u0287',
v : '\u028C',
w : '\u028D',
y : '\u028E',
'.' : '\u02D9',
'[' : ']',
'(' : ')',
'{' : '}',
'?' : '\u00BF', //from pne
'!' : '\u00A1',
"\'" : ',',
'<' : '>',
'_' : '\u203E',
';' : '\u061B',
'\u203F' : '\u2040',
'\u2045' : '\u2046',
'\u2234' : '\u2235',
'\r' : '\n' //thank you, Yeeliberto
}

for (i in flipTable) {
flipTable[flipTable[i]] = i
}
</script>

<html>
<body>
<h2>Text Flipper</h2>
<form name="f">
Original: <textarea rows="5" cols="50" name="original" onKeyUp="flip()"></textarea>
<br>
Flipped: <textarea rows="5" cols="50" name="flipped"></textarea>
</form>
</body>
</html>

Friday, May 8, 2009

Basic AJAX Script

<script language = "javascript">

var XMLHttpRequestObject = false;
if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
}

else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");
}

function getData(dataSource, divID) {
if(XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function() {
if (XMLHttpRequestObject.readyState == 4 && XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
</script>

At the HTML just add this line :
onClick="getData('my_write.php?type=kingston','contentalt')"

  • onClick is an event handler
  • my_write.php is a processing page
  • type=kingston is a parameter passed to my_write.php, named "type" and valued "kingston"
  • contentalt is div id where the result from my_write.php will appears

HTML Escaper Script

<script type="text/javascript">
/*
Simple HTML escaper by Raymond May Jr.
Uses global regex to replace < and > with HTML entities.
http://www.compender.com
*/

function escape()
{
var input = document.getElementById("input").value;

input = input.replace(/&/g,"&amp;");

input = input.replace(/</g,"&lt;");
input = input.replace(/>/g,"&gt;");

document.getElementById("input").value = input;
}

function unEscape()
{
var input = document.getElementById("input").value;

input = input.replace(/&lt;/g,"<");
input = input.replace(/&gt;/g,">");

input = input.replace(/&amp;/g,"&");

document.getElementById("input").value = input;
}
</script>

<html>
<body>
<h2>HTML Escaper</h2>
<form>
<textarea id="input" rows="30" cols="80"></textarea>
<br />
<input type="button" value="Escape!" onClick="escape()" />
<input type="button" value="Un-Escape!" onClick="unEscape()" />
</form>
</body>
</html>

How to Post HTML Code on Your Blog

Ever wanted to post some HTML code in a Blogger post only to find that Blogger does not have code tags? The quick solution is to replace all "<" and ">" characters with their HTML entity equivalents "& lt;" and "& gt;".

Or you can use a simple JavaScript client side HTML escaper. Just paste your HTML code in the textarea and click "Escape!"

Wednesday, May 6, 2009

Apache Error - localhost not working

Well, I've installed Apache 2 on my WinXP system. I currently use Windows Firewall & have checked to make sure it is not blocking Apache. I've tried both AppServ and XAMPP, and I got same error.

I can't find my localhost in the web browser & I've found the size of error log is 200MB with following message in the error log:

[Tue Oct 26 19:33:30 2008] [notice] Parent: Created child process 2384
[Tue Oct 26 19:33:31 2008] [notice] Child 2384: Child process is running
[Tue Oct 26 19:33:31 2008] [notice] Child 2384: Acquired the start mutex.
[Tue Oct 26 19:33:31 2008] [notice] Child 2384: Starting 250 worker threads.
[Tue Oct 26 19:33:31 2008] [error] (OS 10038)An operation was attempted on something that is not a socket. : Child 2384: Encountered too many errors accepting client connections. Possible causes: dynamic address renewal, or incompatible VPN or firewall software. Try using the Win32DisableAcceptEx directive.

This problem can be solved easily, follow this step :
1. On the top of httpd.conf
2. Write this on a separate line : Win32DisableAcceptEx
3. Save the file
4. Restart the apache service
5. Finish