CSS: having a popup appear on graphic mouse over

You have a graphic that if the user mouseovers you want a popup.

How the heck do you do that?

your original code looks like this:

<img align="center" src="img/dracko120.jpg">

You need to declare a div with a lable for the image file and what you want to do

assign a dumy href command (that goes nowhere)
put what you want to do between the span labels.

so my code now looks like this:

<div id="searchpop">
<a href="#">
<img align="center" src="img/dracko120.jpg" />
<span>
<?php $dracko->dsp_search_form(); ?>
</span>
</a>
</div>

Now I have to lay out the css

the first entry in the css is the div id, the a in <a href="#">, the span (this says don’t display)
the second entry tells it what to do on mouse over

#searchpop a span {display: none;}

#searchpop a:hover span {display: block;

position: absolute; top: 200px; left: 0; width: 125px;

padding: 5px; margin: 10px; z-index: 100;

color: #AAA; background: black;

font: 10px Verdana, sans-serif; text-align: center;

}

—have fun
john

How to get a file extension using php

Question : How to get file extension using php
I want to extract the file extentions from a file name. How do i do that from php?

Answer
There are several ways to do that. First is using the combination of strrpos() and substr() function like this :

$ext = substr($fileName, strrpos($fileName, ‘.’) + 1);

For example, if $fileName is my-new-house.jpg then strrpos($fileName, ‘.’) will return the last location a dot character in $fileName which is 15. So substr($fileName, strrpos($fileName, ‘.’) + 1) equals to substr($fileName, 16) which return ‘jpg’

The second is using strrchr() and substr() :

$ext = substr(strrchr($fileName, ‘.’), 1);

strrchr($fileName) returns ‘.jpg’ so substr(strrchr($fileName, ‘.’), 1) equals to substr(‘.jpg’, 1) which returns ‘jpg’

PHP Forms and User Input

PHP Forms and User Input

The PHP $_GET and $_POST variables are used to retrieve information from forms, like user input.
PHP Form Handling

The most important thing to notice when dealing with HTML forms and PHP is that any form element in an HTML page will automatically be available to your PHP scripts.

Form example:

<html>
<body>

<form action=\"welcome.php\" method=\"post\">
Name: <input type=\"text\" name=\"name\" />
Age: <input type=\"text\" name=\"age\" />
<input type=\"submit\" />
</form>

</body>
</html>

The example HTML page above contains two input fields and a submit button. When the user fills in this form and click on the submit button, the form data is sent to the \"welcome.php\" file.

The \"welcome.php\" file looks like this:

<html>
<body>

Welcome <?php echo $_POST[\"name\"]; ?>.<br />
You are <?php echo $_POST[\"age\"]; ?> years old.

</body>
</html>

A sample output of the above script may be:

Welcome John.
You are 28 years old.

The PHP $_GET and $_POST variables will be explained in the next chapters.
Form Validation

User input should be validated whenever possible. Client side validation is faster, and will reduce server load.

However, any site that gets enough traffic to worry about server resources, may also need to worry about site security. You should always use server side validation if the form accesses a database.

A good way to validate a form on the server is to post the form to itself, instead of jumping to a different page. The user will then get the error messages on the same page as the form. This

Solve PHP Fatal error: Allowed memory size of 8388608 bytes exhausted

This error message can spring up in a previously functional PHP script when the memory requirements exceed the default 8MB limit. Don’t fret, though, because this is an easy problem to overcome.

To change the memory limit for one specific script by including a line such as this at the top of the script:

ini_set("memory_limit","12M");

The 12M sets the limit to 12 megabytes (12582912 bytes). If this doesn’t work, keep increasing the memory limit until your script fits or your server squeals for mercy.

You can also make this change permanently for all PHP scripts running on the server by adding a line like this to the server’s php.ini file:

memory_limit = 12M

Keep in mind that a huge memory limit is a poor substitute for good coding. A poorly written script may inefficiently squander memory which can cause severe problems for frequently executed scripts. However, some applications are run infrequently and require lots of memory like importing and processing a big data file.

Browser Redirect

Browser Redirect
Learn how to do a Browser Redirect using the power of PHP.

Sponsors – Spoono Host
Alright, this is a simple little script which will take you to one page if you’re using Internet Explorer, and another page if you’re using some other browser. Lets decide what this is going to do in English:

1. If the browser is MicroSoft Internet Explorer (MSIE), then go to spoono.com
2. If the browser isn’t MSIE, then redirect to yahoo.com.

The most essential part of this is that this code has to be sent out before any output to the HTML page. Make sure it is the first line of code on your PHP page. With that said, here is the PHP:

Its not as hard as it looks in the beginning, is it? Simple and easy to do.

PHP Errors and How to Fix Them

Errors and How to Fix Them
This tutorial will briefly describe some of the common errors in PHP.

Sponsors – Spoono Host
I get a myriad of e-mails from visitors who get a particular error whenever they’re coding, or doing one of the PHP tutorials. Most of the errors which people get are very similar so I thought I’d go through some of the most common errors, what causes them, and how to fix it. The three most common error types are:

1. Parse Errors
2. Header Errors
3. mySQL Result Source Errors

Parse Errors
What Error Says:
Parse error: parse error, unexpected T_STRING in /home/virtual/site5/fst/var/www/html/akash/errors.php on line 11

Cause of Error
A parse error is a runtime error whenever the PHP compiler is trying to compile your code. Its usually something simple, and can usually be fixed fairly easily. The problem is the syntax of your code, perhaps you forgot a semi-colon on one of the lines. Another infamous parse error is forgetting a double quote (") or an end bracket (}) after you started one. In that case, the error will not be on the line where the brace of quote should be, but might be at the end of your program.

How to Fix Them
Well, the easiest way to go about fixing parse errors is to find the line which PHP is saying caused the error. If you notice that you forgot a simple semi-colon, then insert it and you’ll be on your way. If the line it says is the last line of your code, then you need to go back and look through your code to see if all the { } and " are set up properly. One way to check the brackets is to tab them properly and see if they line up. To check for the ", you can try to use a color coded editor, which will usually indicate anything inside a " in a different color.

Header Errors
What Error Says:
Warning: Cannot add header information – headers already sent by (output started at /home/virtual/site5/fst/var/www/html/akash/errors.php:9) in /home/virtual/site5/fst/var/www/html/akash/errors.php on line 10

Cause of Error
HTTP Headers are specific functions defined by PHP which are required to be sent before any output from your script. This means that if it is a header function, then you must place it before any physical output, such as or even a whitespace. Fortunately, there aren’t too many header functions out there, but if you get this error, then I guess you’ve found one. Two of the most important ones are the redirect function in PHP:
Header("location: http://ww.spoono.com");
and the
setcookie()
function.

How to Fix Them
Chances are that if you have a header error, you’re trying to pull a function that’s supposed to be before any other ouput in your file after you’ve placed an output. Go to the line where the error is, select that section and punch it up to the top of your code. Also, if you must have an output before the header function, there is an alternative. Place the code
at the top before any other text, and then place
later on near wherever you must run the header script. That should be about it.

mySQL Result Source Errors
What Error Says:
Warning: Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/virtual/site5/fst/var/www/html/tutorials/php/error/index.php on line 3

Cause of Error
Contrary to what the line number might say, this error is sort of tricky because more times than not, the error occurs on the $result variable you use to define the loop. For example say your code looks like the following:

The problem displayed would be with the mysql_fetch_array() function on the while loop. However, the real problem is that the $result variable misspells the word "order" on line 1. The $result variable is not executed till the while loop runs on line 3, which is why the error line is given on that line.

How to Fix Them
The first thing to do when you see the mySQL Resource error is to go to the line which PHP says is causing the problem. Next, make sure that the syntax on the line is right, more times than not it will be. Now, the main thing to check where most of the problem usually hides is inside the $result variable definition. For example, on our code up there, the problem is not on the
where PHP says it is, but rather on the $result variable defined above it. 99.9% of the time, there is a problem with that, whether it be something misspelled or undefined. To find out the particular problem, you can replace your $result with the following code:
, which will display the cause of the error. Go check and fix that and you’ll be on your way.

makes and/or adds data to files on your server using PHP

File Creator/Editor
Create a form that makes and/or adds data to files on your server. Could be useful in creating a simple guestbook and free for all links flat file database.

Sponsors – Spoono Host
With this code, you can make a form that writes to a file. You can create files of just about any type, because you can define the file name. You need to be sure that you are in a Linux server and have CHMODed the directory to 777. This tutorial is broken into two parts, one for the form, and one for the action for the form. The form part is easy enough. On an HTML page, copy paste the following form. Save it in the same directory as you will want to create your page. The form has input fields, such as the file name and body of the file you are creating and the submit button:




Once you have your form done, you can make the action.php file refered to in the form tag.
The code in the action.php is just code the uses the fwrite() function in php. All you need is to have something like this:

What the above code code does is gets the file name you specified in the form, opens or creates it, then adds the data you entered. If the file already exists, then it’ll add on to the bottom of that file. The stripslashes code is to make the html code work properly, so leave it there.

how to make a comment/discussion board in PHP

Comment Board
This is a tutorial that shows you how to make a comment/discussion board like those on this site using PHP and mySQL. there are three files: comments.php, which displays the comments, commentadd.php, which processes the comment, and commentform.html which is simply a form that can be placed in any page manually or per SSI (server side includes). I realize that it is possible to have all three components in one file, but we are using this multifile method for tutorial functionality

Sponsors – Spoono Host
The Database
First, you need to create a database called "comments"
Then, use this code to create the table:

CREATE TABLE `comtbl` (
`postID` INT NOT NULL AUTO_INCREMENT ,
`postTITLE` TEXT NOT NULL ,
`posterNAME` TEXT NOT NULL ,
`posterEMAIL` TEXT NOT NULL ,
`postTIME` TIMESTAMP NOT NULL ,
`postTXT` TEXT NOT NULL ,
PRIMARY KEY ( `postID` )
);

The Comment Viewing Page COMMENTS.PHP
First we need to connect to the database/table, where username/password correspond to your username and password: r

$dbcnx = mysql_connect("localhost", "username", "password");
mysql_select_db("comments");

Next, we need to query the table, and sort it by ID Descending:

$result = mysql_query("SELECT * FROM comtbl ORDER BY postID DESC");
if (!$result) {
echo("Error performing query: " . mysql_error() . "");
exit();
}

Now we have fields to send into variables; and because we want it to show posts, we need a while loop (which repeats the query until the table completely read):

while ($row = mysql_fetch_array($result) ) {
$msgTxt = $row["postTXT"];
$msgId = $row["postID"];
$SigName = $row["posterNAME"];
$SigDate = $row["postTIME"];
$msgTitle = $row["postTITLE"];
$url = $row["posterEMAIL"];

Ok. now here’s the hard part: because i decided to use MySQL’s TIMESTAMP fuction (which automatically enters the time of an addition to a table), i need to split up the postTIME string using the php substr() function (where $yr will give the year, $mo the month, etc):

$yr = substr($SigDate, 2, 2);
$mo = substr($SigDate, 4, 2);
$da = substr($SigDate, 6, 2);
$hr = substr($SigDate, 8, 2);
$min = substr($SigDate, 10, 2);

Now since not everyone is familiar with military time, we have to replace hours like 15 and 22 with more user-friendly noes like 3 and 10, but at the same time add PM if its past noon, and add AM if its not:

if ($hr > "11") {
$x = "12";
$timetype = "PM";
$hr = $hr – 12;
}else{
$timetype = "AM";
}

Heres the last bit before we actually display the data. If the user decides to leave the Email field blank, we’ll insert a ‘#’ into the link on his name. If he filled it out, then we’ll insert the ‘mailto:’ in front of the email address:

if (!$url) {
$url = "#";
}else{
$stat = $url;
$url = "mailto:" . $url . "";
}

FINALLY, we get to display the row of data, and close out the loop, thus finishing the php. Here the code is followed by an example of how it will be printed (please realize that you can change how it looks at any time just by moving the variables within the echo statement)

echo("

$msgTitle $msgTxt

$hr:$min $timetype | $mo/$da/$yr | $msgId, $SigName

");
}

Message Title Text within the message, blah blah

Hour:Minute AM/PM | Month/Day/Year | Message ID, Name with email link

Form Processing: COMMENTADD.PHP
Whew! Ok this file does the actual processing (adding) of the comments. First we’ll set the variables passed through HTTP Post into a variable, then insert it into the database. Please remember to change the username and password.

$assume = $_POST[‘assume’];
$posterEMAIL = $_POST[‘postemail’];
$postTXT = $_POST[‘posttxt’];
$posterNAME = $_POST[‘poster’];
$postTITLE = $_POST[‘posttitle’];

if ($assume == "true") {

$dbcnx = mysql_connect("localhost", "username", "password");
mysql_select_db("comments");

$sql = "INSERT INTO comtbl SET posterNAME=’$posterNAME’, posterEMAIL=’$posterEMAIL’,
postTXT=’$postTXT’, postTITLE=’$postTITLE’";

if (mysql_query($sql)) {
echo("

Your comment has been added

");
} else {
echo("

Error adding entry: " . mysql_error() . "

");
}
}

OK, thats it for PHP, now all we need is some javascript to make it go right back to the comments page or to any other page you want (remember to close ur php tags!):

OK! Heres for the form! COMMENTFORM.HTML This is basically just a form that sends all the data into commentadd.php to be processed.