Form validation using php regular expression

PHP form validation is important because if any one inactivate javaScript, then can pass garbage value. So we need to check it for filtering. Simple example:   <?php if($_POST){ $name = $_POST['name']; $email = $_POST['email']; $username = $_POST['username']; $password = $_POST['password']; $gender = $_POST['gender']; // Full Name if (eregi(‘^[A-Za-z0-9 ]{3,20}$’,$name)){ $valid_name=$name; }else{ $error_name=’Enter valid Name.’; [...]

Continue Reading...

how to create .dat file using PHP

Some time we need to convert html text to MS-Word document. I am doing this sort of job in a simple way. An easy example for you: <form action=”doc_action.php” method=”post”> <textarea name=”word_doc” cols=”50″ rows=”15″></textarea><br /> <div>Your Doc file name : <input type=”text” name=”file_name”><br> Save ocation : <input type=”text” name=”location”> (D:\personal\)<br> <input type=”submit” name=”submit” value=”Convert doc” [...]

Continue Reading...

member function prepare() on a non-object : member function Execute() on a non-object

I want to read data from an excal sheet and insert in my mySql database using $sql = $dbh->prepare(“INSERT INTO rutas_programadas (first, middle, last, email) VALUES(?, ?, ?, ?)”); I found such type of problem. But i overcome it in this ways: $sql = ‘INSERT INTO names VALUES(“”,”‘. $first .’”,”‘ . $middle . ‘”,”‘ . [...]

Continue Reading...

Make your URL secured: Protect URL injection

Make your URL secured: Protect URL injection Naturally we pass values from one page to another page by using encore tag, as like <a href=”action.php?name=saiful&language=php & frame_work = ci & cms =joomla”>action</a> After passing the URL shows in action page as like: http://localhost/practice/1/action.php?name=saiful&language=php&frame_work=ci&cms=joomla Or header(‘Location: action.php?name=’ . urlencode(saiful) . ‘& language =’ . urlencode(php) . [...]

Continue Reading...

Display local time

Some time we need to echo (display) our local time. If we use displays the GMT time. So to get local time i use the following time function: <?php class MyTimeZone { const TIMEZONE_SERVER_OFFSET = +6; // your server’s offset from GMT 0 for Bangladesh +6 public function timeOffset($offset = null) { if (is_int($offset)) { [...]

Continue Reading...