Posts

Showing posts from September, 2015

Using PHP_SELF in the action field of a form to submit php form

In this article shows the usage of PHP_SELF variable and how to avoid PHP_SELF exploits. What is PHP_SELF variable? PHP_SELF is a variable that returns the current script being executed. This variable returns the name and path of the current file (from the root folder). You can use this variable in the action field of the FORM. There are also certain exploits that you need to be aware of. We shall discuss all these points in this article. We will now see some examples. echo $_SERVER['PHP_SELF']; a) Suppose your php file is located at the address: http://www.yourserver.com/form-action.php In this case, PHP_SELF will contain: "/form-action.php" b) Suppose your php file is located at the address: http://www.yourserver.com/dir1/form-action.php For this URL, PHP_SELF will be : "/dir1/form-action.php" Using the PHP_SELF variable in the action field of the form A common use of PHP_SELF variable is in the action field of the <form> tag.

PHP MySQL search using radio option

Image
<?php include 'includes/config.php'; ?> <?php if(isset($_POST['submit'])){ $pickup=isset($_POST['pickup'])?$_POST['pickup']:''; $dropoff=isset($_POST['dropoff'])?$_POST['dropoff']:''; $traveltype=isset($_POST['traveltype'])?$_POST['traveltype']:''; $sql = "SELECT * from availablecabs where pickup='$pickup' AND dropoff='$dropoff' AND traveltype='$traveltype'"; $result = $conn->query($sql); if ($result->num_rows > 0) { ?> <?php  while($row = $result->fetch_assoc()) {     $indica=$row['indica'];             }    } else {} } ?> <form class="input-daterange" data-date-format="M, d" method="POST" action="car-search.php">                             <div class="form-group form-group-icon-left"><i class="fa fa-map-marker input-icon input-icon-h

N-Level of Dynamic Loading of DropDowns using Ajax and PHP. Part 2

Image
This is version 2 of my previous tutorial which was dynamic loading of combos with Ajax . But its much more than that. Its now for n-level dropdowns, I mean if you have parent-child records untill n-level and you want to load them using dropdowns with ajax. It is my favorit tutorial and very useful for any one. We often needs ajax loading of dropdowns and this is for n-level records. Hope you will like it. Cheers ! PHP $(document).ready(function() { //$('#loader').hide(); $('.parent').livequery('change', function() { $(this).nextAll('.parent').remove(); $(this).nextAll('label').remove(); $('#show_sub_categories').append('<img id="loader" style="float: left; margin-top: 7px;" src="loader.gif" alt="" />'); $.post("get_chid_categories.php", { parent_id: $(this).val(), }, fun

Ajax Tutorial: Dynamic Loading of ComboBox using jQuery and Ajax in PHP

Image
Here is a script for beginners to create a dynamic loading of dropdown. Simple solution which is created by jQuery. PART TWO IS HERE [ad#ad-3] Table Structure PHP CREATE TABLE IF NOT EXISTS `ajax_categories` ( `id` int(11) NOT NULL AUTO_INCREMENT, `category` varchar(50) NOT NULL, `pid` int(11) NOT NULL, PRIMARY KEY (`id`) ) 1 2 3 4 5 6 CREATE TABLE IF NOT EXISTS ` ajax_categories ` (    ` id ` int ( 11 ) NOT NULL AUTO_INCREMENT ,    ` category ` varchar ( 50 ) NOT NULL ,    ` pid ` int ( 11 ) NOT NULL ,    PRIMARY KEY ( ` id ` ) ) get_child_categoires.php PHP <?php if($_REQUEST) { $id = $_REQUEST['parent_id']; $query = "select * from ajax_categories where pid = ".$id; $results = mysql_query( $query);?> <select name="sub_category" id="sub_category_id"> <option value="" select

How to Keep the selected value of the select box after Form POST or GET

<? php $example = $_POST [ "friend" ]; ?> <form method = "POST" > <select name = "friend" > <option value="tom" <? php if ( isset ( $example ) && $example == "tom" ) echo ' selected' ;?> >Thomas Finnegan </option> <option value="anna" <? php if ( isset ( $example ) && $example == "anna" ) echo ' selected' ;?> >Anna Karenina </option> </select> <br><br> <input type = "submit" > </form

php echo default value if not from database

<?php echo $sedan ? $sedan:'800'  ?>

Fetching data from MySQL database using PHP Displaying it in a form

<html> <head> <title> Delegate edit form </title><br /> </head> <body> Delegate update form <p> <? php $usernm = "root" ; $passwd = "" ; $host = "localhost" ; $database = "swift" ; //$Name=$_POST['Name']; //$Username=$_POST['User_name']; //$Password=$_POST['Password']; mysql_connect ( $host , $usernm , $passwd ); mysql_select_db ( $database ); $sql = "SELECT * FROM usermaster WHERE User_name='$Username'" ; $result = mysql_query ( $sql ) or die ( mysql_error ()); while ( $row = mysql_fetch_array ( $result )){ $Name = $row [ 'Name' ]; $Username = $row [ 'User_name' ]; $Password = $row [ 'User_password' ]; } ?> <form action="Delegate_update.php" method="post" Name <input type="text" name= "Name" value= " <? php echo $Name ; ?> "

How to style a dropdown with CSS only without JavaScript

    Using -moz-appearance with the none value on a combobox now remove the dropdown button So now in order to hide the default styling - it's as easy as adding the following rules on our select element:   <style> select { - webkit - appearance : none ; - moz - appearance : none ; appearance : none ; } select ::- ms - expand { /* for IE 11 */ display : none ; } </style>

multiple image upload to server using php mysql

index.php <!DOCTYPE html> <html> <head> <title> Dynamically create input fields- jQuery </title> <script  src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js"></script> <script type="text/javascript"> $(function() {         var addDiv = $('#addinput');         var i = $('#addinput p').size() + 1;         var max_fields=10;                 $('#addNew').live('click', function() {         if(i<max_fields){                 $('<p><input type="file" id="myimage" size="40" name="myimage' + i +'" value="" placeholder="I am New" /><a href="#" id="remNew">Remove</a> </p>').appendTo(addDiv);                 i++;                 }                                 return false;         });                 $('#remNew').live('click', funct

HOW TO REMOVE NOTICE "UNDEFINED INDEX" ?

Add this at the top of your file <?php error_reporting (E_ERROR | E_PARSE); ?>

Dynamically Add Input Fields To Form Using jQuery

Image
As jQuery is so powerful and it is easy to learn, it attracts huge volume of web developers. In this post I will show how to dynamically create input fields in a web page. Well you can use the logic to create other elements dynamically in a webpage . You can check the LIVE DEMO . You can use my tutorial on inserting record in database using jQuery and php and combine it with this tutorial to create a wonderful dynamic form accepting inputs from user and insert it in your database. The code is pretty easy to interpret and understand how it works. Here is our code: view source print ? 1 <html> 2 <head> 3 <title> Dynamically create input fields- jQuery </title> 4 <script  src= " https://<span class=" IL_AD " id=" IL_AD7 ">ajax</span>.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js" ></script>        // Calling jQuery Library hosted on Google's CDN 5 <

Add/Remove Input Fields Dynamically with jQuery

Image
If you are looking to add and remove duplicate input fields, here’s another jQuery example below to do the task for you. This jQuery snippet adds duplicate input fields dynamically and stops when it reaches maximum. If you read comment lines carefully, the process is pretty straight forward. We start with 1 input field and let user add more fields until the count reaches maximum. Same process goes to delete button, when clicked, it removes current text field by removing the parent element, which is div element. jquery 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 $ ( document ) . ready ( function ( ) {     var max_fields       = 10 ; //maximum input boxes allowed     var wrapper         = $ ( ".input_fields_wrap" ) ; //Fields wrapper     var add_button       = $ ( ".add_field_button" ) ; //Add button ID         var x = 1 ; //initlal text box count     $ ( add_button ) . click ( function ( e ) { //on add inpu