Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

Monday, 10 January 2011

Access violation at address 10002593 in Module 'LIBMYSQL.dll'

When you install WinMySQLAdmin with MySQL and start WinMySQLAdmin you end with this error. Every time you start the control application you get a warning which is repeated until WinMySQLAdmin is shut down.

Access violation at address 10002593 in Module 'LIBMYSQL.dll'
Repeating the Error

Start WinMySQLAdmin with the xampp and you should get the error again.

Solution

1. Open WinMySQlAdmin
2. Click on the my.ini Setup tab
3. Change the following entries

user=root
password=password

to

user=
password=

Another simple solution is to locate my.ini in your windows directory and make the below changes:

user=root
password=password

to

user=root
password=


This should resolve the error. If not, let me know and I will try my best to get you another solution. :)

Generating XHTML MP (WAP 2.0) Pages From PHP

XHTML Mp Webpage Generation Using PHPMaybe you guys know that I've been working on a service called MyWapBlog.com which lets peoples create/manage mobile blogs using their mobile phones. In the course of the development I've learnt great deal about mobile websites and their dynamic generation, and I'm sharing a bit of it here in this post.

How do you generate dynamic (X)HTML Pages using PHP? Simple:









Sometitle





Hello



echo date('h:i A, j-M-y'); ?>







And if you look at XHTML MP pages, their source look like the following:











...

...

So you see these pages have a different document type and some other differences. So will the following code work and generate a valid WAP 2.0 page?:









Sometitle





Hello



echo date('h:i A, j-M-y'); ?>





The answer is “NO”? Why? Because XHTML MP pages needs to be served with a different Content-Type than what is generated by .PHP files. Normally when you runa s PHP script and it outputs something, the content is served with Content-Type: text/html

What is Content-Type?

It is a header (information about a particular resource) returned to browser when it requests something from a server. When you request an image, the server return the image with the header image/png, image/jpeg etc. letting the browser know how the returned content is to be interpreted.

PHP scripts can return contents of any type (using the header() function), from text to images and PDFs to ZIPs. And therfore if we want to generate XHTML MP pages, it can even do that without doubt.

So what we need to do is, just change the above code a bit adding a new line at the top so that the whole code look like the following:



("Content-type: application/vnd.wap.xhtml+xml; charset=UTF-8");?>









Sometitle





Hello



echo date('h:i A, j-M-y'); ?>





This will tell the browser that the content we are going to serve is of the type XHTML MP. We always use the charset UTF-8 for these pages, which is also told to the requesting browser.

Now the big question is, why we didn't do this for normal HTML pages. Why didn't we have to tell the browser that content is of the type “text/html” when it was so? Because PHP does it for us! Yes whenever we output anything from PHP scripts, the PHP interpreter outputs the default header (text/html) automatically. Just as the PHP interpreter finds anything in the script that needs to be output, it first generates a header, the outputted content follows. For example in the first script, the very first line (very first character “<”) needs to be output to the browser. So before that, the PHP interpreter sends a content type header (default – text/html).

Therefore, when we had to output our content with a different header we had to make sure that it is done before PHP does it automatically. Two headers cannot be valid.

This is it for this post, do check back soon for more new posts. Till then, good bye!

Creating Tool-Tip Text for WebPages Using CSS Only

Creating Tool-Tip Text for WebPages Using CSS Only

[You might also be interseted in Deigning a Simple HTML Menu-Bar Using CSS]

All right, so today we are going to use CSS along with some HTML to create Tooltip text for WebPages without using JavaScript. Yeah, you heard it right using only CSS and of course HTML. Do I need to explain what a Tooltip is, BTW? Nah, you guys already know it. I do not think many sites use tooltips or anything of that sort on their websites but in case you do or you just want to learn, read on…

Well, the first thing that I want to tell is that the basic technique I’ll be using to create tooltips is not mine, I saw someone using it for a slightly different purpose, I changes it to suite mine. As I said earlier we’d be using CSS and HTML only, I guess HTML is easier so here it is:

href="#" class="tooltip">Hover Here>This is the Tool-Tip Text>>

As you can see there is nothing special, a plain simple link but wait what is that for? Good question! Well the text under the tag wouldn’t be visible unless you hover the mouse over the link. When you do so that’d become visible, neatly formatted to look just like a real Tooltip text. But how? You might ask. It has been classified (class="tooltip") to do so.

The heart of all this is the CSS:

   a.tooltip{     /* for postioning the tool-tip box relative to the link */     position:relative;      /* no underline needed */     text-decoration: none;   }    a.tooltip span{     /* tool-tip text will not be visible initially */     display: none;   }    a.tooltip:hover span{     /* make tool-tip text visible */     display:block;      /* for postioning */     position:absolute;     top:20px; left:20px;     padding: 5px;      /* width of the tool-tip box     if text is longer, it will be     made into two lines */     width:150px;      /* style the box to look like a tool-tip box */     border:1px solid #000;     background-color:#FFFFAA;     color:#000;   }  

Now to make it more clear, I’d break the whole code into smaller pieces and discuss what that does:

1.

a.tooltip { position:relative; }

This would make the tooltip (whenever) it appears to be positioned relatively to where the link is.

2.

a.tooltip span { display: none; }

It’d (as you might have guessed) make the tooltip text (or the tag) to be invisible.

3.

  a.tooltip:hover span {       display:block;      position:absolute;      top:20px;      left:20px;      padding: 5px;      width:150px;     border:1px solid #000;      background-color:#FFFFAA;      color:#000;    }

This defines what the tag would be when mouse is hovered over the link.

First it’d make the visible (thus the tooltip text) by using display: block;. Next it’d position and style the text to look like a “Real” tooltip.

Easy! Now it is…

Here is the complete code:

   >   >    >ToolTip Text Example>   

Saturday, 9 October 2010

PHP Tutorial: Writing A Feedback Form Script Getting Started with PHP: Write a FormMail Script in PHP

PHP Tutorial: Writing Your First PHP Script: Feedback Form Script

by Christopher Heng, thesitewizard.com

I have always believed that the most fun way to learn a new programming language, whether it is a language like C or a scripting language like PHP, is to use it to write a real-life useful program. Of course this is not the most systematic method of learning, but it works well if you already have some background in programming.

Preliminaries

  1. Before you write your first PHP program, make sure that that your website is running on a web host that runs PHP 4.1 or above.

  2. You may also find it useful to have a copy of PHP 4.1 or later installed on your own computer. This makes testing your PHP scripts much easier. If you use Windows, you can find some tips on installing PHP on your own computer from my article on "How to Install and Configure PHP 5 to Run with Apache on Windows" at http://www.thesitewizard.com/php/install-php-5-apache-windows.shtml

  3. And of course, you will need an ASCII text editor of some kind (such as Notepad on Windows). There's a list of such editors on http://www.thefreecountry.com/programming/editors.shtml

  4. This tutorial also assumes that you have at least some knowledge of HTML. This is necessary because if I have to explain all the HTML tags as well, this tutorial will end up being tediously long.

  5. You'll probably need a bit of programming background, or at the very least, an aptitude for computer programming. Note that being able to code in HTML does not count, since HTML is not a programming language. Unlike the majority of the other articles on thesitewizard.com, this article is not targeted at the absolute newcomer. You really need background in both web design using HTML and a bit of programming skill/aptitude, otherwise this article will be indecipherable. If you are reading this article because you want to create a website, please start with How to Make / Create Your Own Website: The Beginner's A-Z Guide instead.

I will begin with a very rudimentary (but working) PHP script to take input from a feedback form and send it to you in an email message. This type of form is sometimes referred to as a FormMail or Form to Mail script. In later articles, I will develop that script (and others) to include features commonly found in such FormMail scripts.

If you are programming-savvy, you will recognize this as a sort of "Hello World" program, but infinitely more useful!

Writing the Feedback Form

The first thing we need to do is to write the feedback form itself. Put the following code in the section of an HTML file named, say, feedback.html.

Email:
Message:

Basically the form asks the visitor for his email address (the field named "email" found in input name="email" above) and message (the field named "message" found in textarea name="message"), and presents him with a button which he can click to submit the contents of the form. When the form is submitted, it is "posted" (see the "method" attribute of the

tag) to a script named "sendmail.php" (also specified in the tag).

The Feedback Form PHP Script

Now all that remains is to code "sendmail.php". This is made extremely easy by the facilities available in PHP. Type the following code into a file named "sendmail.php". Do not put anything else into that file, ie, don't put in any other HTML tags or headers, etc.

 

When the form is submitted to sendmail.php, the contents of the "email" field in the form is put into a PHP variable called $_REQUEST['email']. Likewise the contents of the "message" field is put into the variable $_REQUEST['message'].

If you had named the fields in your form "emailofsender" and "contentsofmessage", then the information submitted in those fields would have been available to your script in the variables $_REQUEST['emailofsender'] and $_REQUEST['contentsofmessage'] respectively. I think you get the idea.

The first thing we do in our PHP script is to make the information that is submitted easily accessible to the rest of the program.

Firstly, we made a copy of the contents of $_REQUEST['email'] in a variable we call $email. This was done in the line

$email = $_REQUEST['email'] ;

Note that we don't really have to call this new variable $email. We could have called it $thingamajig if we wished, but it makes sense to name a variable with some meaningful name.

Likewise, in the next line, we made a copy (assigned) of $_REQUEST['message'] in a variable $message.

$message = $_REQUEST['message'] ;

Again, we could have named the new variable anything we wanted — but it's easier for us to understand the program if the variable name reflects what it does.

The real workhorse of this script is in the line beginning with "mail".

mail( "yourname@example.com", "Feedback Form Results",   $message, "From: $email" ); 

mail is a special function in PHP that sends mail. The first parameter to mail is supposed to contain the email address you want the form contents to be sent to, such as your own email address. The second parameter is the "Subject" of the email message. The last two parameters are the content of the message and the headers you want sent, respectively. We want a "From" header so that we know who is sending the email to us and can reply to him/her if we need to.

Notice that, like many other programming languages, strings (sequences of characters) are enclosed in double quotes, such as "Feedback Form Results".

Variables like $message can be used as-is. Note also that you can also interpolate (introduce) the contents of the variable $email into a string, like "From: $email", so that if your $email string contained an address like "william@shakespeare.com", the final string that is passed to the mail function will be "From: william@shakespeare.com".

You can also use single quotes (such as those in 'Hi there') to quote strings, but when you do so, the variables included are not expanded. This is useful if, for some reason, you really want to pass the string 'From: $email' to mail without PHP translating that to "From: william@shakespeare.com".

Finally, it is appropriate to thank the visitor for his message. This is done with the line

header( "Location: http://www.example.com/thankyou.html" );

This line causes PHP to send an HTTP header back to the visitor's browser telling it to load the URL "http://www.example.com/thankyou.html". The "header" function allows us to send any HTTP header to the browser.

You will of course have to create such a file called "thankyou.html" with some sort of message to thank your visitor for his efforts, otherwise your visitor will be greeted with an unfriendly "404 File Not Found" error after he sends his message. You should also replace the URLs and email addresses with the correct ones if you want to use that script on your site.

By the way, the script has to be enclosed within the "" and "?>" tags because the PHP processor treats all input as HTML code unless otherwise specified. On most systems, you can simply use "" and "?>" as the opening and closing tags to get the script to work, however if you want to be sure that your script will work on all systems, you should use the full "" form for the opening tag.

Easy wasn't it? In just a few lines, you've written your first PHP script. And it's not some trivial and useless script — it is actually a working, usable program.

Before you put the script "live" on the Internet, check out the following additional tutorials:

  • In How to Improve Your Form to Mail Script, you will develop the script so that your visitor's input is checked to catch instances where someone accidentally clicks the "Submit" button before they fill in their email address. You will also learn how to integrate both the form and the script into a single "feedback.php" file if you wish.

  • The article How to Prevent Email Injection in Your PHP Form to Mail Scripts deals with the security aspects of putting a PHP form to mail script "live" on the Internet, where spammers can abuse it and hijack it to send spam to others.

Copyright 2000-2010 by Christopher Heng. All rights reserved.

Get more free tips and articles like this, on web design, promotion, revenue and scripting, from http://www.thesitewizard.com/