Tag: php

A complete database class in PHP

In this code, we present a database class that can be easily used to perform any operation on database, e.g., select, insert, update, delete, etc. The following is the code of database class: filename: include/functions.php <?php include("db/opendb.php"); $msg = NULL; /// STARTING CODE OF Database Class ///////// class Database { public $pstmt=NULL; function FetchRecord($query) {

ajax based nested drop down and searching

In this example, we present two uses of ajax. In first use, we created an ajax based nested drop downs which are also databased enabled. In second use, we create a keyword list suggestion in ajax (as we see in google search box). For this example, we used the following database: ajaxexample.sql SET SQL_MODE =

ajax based input form in php

In this example, we create an ajax based input form. The form is not submitted to the server, rather, its values are stored in the database using ajax without submitting form. default.php <html> <head> <title></title> <script type="text/javascript" src="ajax_javascript.js"></script> </head> <body> <form id="frm" name="frm" method="post" action=""> <table border="1"> <tr> <td>City</td> <td><input id="txtcity" name="txtcity" type="text"></td> </tr> <tr>

simple ajax example in php

AJAX stands for Asynchronous Javascript And XML. With ajax, we do need to submit whole form to php, rather, we can send information from a portion of form and receive the response. In this way, the communication cost and delay in submitting the form and receiving response can be significantly reduced. The following program uses

file/directory operations in php

We can do numerous file directory operations in PHP. To delete a file “unlink” function is used. In below program, we can see different operations, we can uncomment code to see the behavior. <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php $dir = "tasks/"; // to delete a single file unlink("tasks/temp.txt"); //

object oriented Inheritance in php

We can use Objected Oriented Programming model in PHP which has rich set of features. Here an example of inheritance in PHP is presented: <!doctype html> <html> <head> <meta charset="utf-8"> <title>Untitled Document</title> </head> <body> <?php class ParentClass { function ShowInParent() { echo "This is in Parent Class<br>"; } } class MyClass extends ParentClass { function

How to prevent SQL injection attacks in PHP

To prevent SQL injection attacks or javascript attacks in your PHP web application, always use parameterized query with prepared statements like: $txtuserid = htmlspecialchars(addslashes(trim($_POST['txtid']))); $query = "select * from users where userid=:userid" try { $stmt = $conn->prepare($query); $stmt->bindParam(':userid', $txtuserid); //$txtuserid getting value through $_POST or URL string $stmt->execute(); echo "Record inserted successfully..."; } catch(PDOException $e)