How to add Textbox dynamically in php

I will show you how to add textbox, select, or any checkbox dynamically in PHP. I will show you how to add dynamic textbox while clicking on link.

<head>
<script language="javascript" type="text/javascript">
function add_textbox()
{
      document.getElementById("data").value="<input type='text' name='name'>";
}
</script>
</head>
<body>
<a onClick="add_textbox()">Add Textbox</a>
</body>

We can easily add all types of inputs dynamically.

Thank you

Premal Katigar
Advertisements

Adding select option dynemically in php with mysql

Just Check out my this post. Its all about dynamically generation of select option. when we select the particular country it should generate automatically the new select option of the states of the particular country.

Create first connectivity.php file. following is the coding for connectivity.

<?php
$con=mysql_connect("Localhost","root");
mysql_select_db("jobsindia",$con);
?>

Now goto localhost/phpmyadmin.

Create database named jobsindia.

Create tables named location_country, location_state

mysql_table

mysql_2

<?php
include 'connectivity.php';
$location=$_GET['loc'];
$email=$_GET['email'];
$paasword=$_GET['pwd'];
?><head>
<script type="text/javascript">
function reload(form)
{
var val=form.loc.options[form.loc.options.selectedIndex].value;
var pwd=document.form.pwd.value;
var email=document.form.email.value;
self.location='registration.php?loc=' + val+"&email="+ email+"&pwd="+pwd;

}
</script>

</head>
<body class="body1">
<form name="form" method="post">
 <td>Where are you currently Located:*</td>
 <td><select name="loc" id="location" onChange="reload(this.form)">
<?php


 $query="select name,id from location_country";
 $result=mysql_query($query);
 if($result)
 {
 ?>
 <option value="">SELECT</option>
 <?php
 while($row=mysql_fetch_array($result))
 {
 if($row[0]==$location)
 {
 
 ?>
 <option value="<?php echo $row[0]; ?>" selected><?php echo $row[0]; ?></option>
 <?php
 }
 else
 {
 ?>
 <option value="<?php echo $row[0]; ?>"><?php echo $row[0]; ?></option>
 <?php
 }
 }
 
 }
 

 ?>
 </select>
<?php 
 $query_country="select id from location_country where name='$location'";
 $result_country=mysql_query($query_country);
 if($result_country)
 {
 $id_country=mysql_fetch_array($result_country);

 }
 ?> 

 
 
 </td>
 <td>&nbsp;</td>
 </tr>
 <?php
 if(!$location=="")
 {
 if($location=="India")
 {
 ?>
 <tr>
 <td>Select Your State:*</td>
 <td><select name="state">
 <?php

 $state_query="select name_state from location_state where id=1";
 $result_state=mysql_query($state_query);
 if($result_state)
 {
 ?>
 <option value="">SELECT</option>
 <?php
 while($row_state=mysql_fetch_array($result_state))
 {
 ?>
 <option value ="<?php echo $row_state[0];?>"> <?php echo $row_state[0];?></option>
 <?php
 }
 
 }
 else
 {
 echo "ERROR";
 }
 ?>
 </select></td>
 <td>&nbsp;</td> 
 </tr>
 <?php
 }
 }
 ?>
<?php
 if(!$location=="")
 {
 if($location=="India")
 {
 ?>
 <tr>
 <td>Select Your State:*</td>
 <td><select name="state">
 <?php

 $state_query="select name_state from location_state where id=1";
 $result_state=mysql_query($state_query);
 if($result_state)
 {
 ?>
 <option value="">SELECT</option>
 <?php
 while($row_state=mysql_fetch_array($result_state))
 {
 ?>
 <option value ="<?php echo $row_state[0];?>"> <?php echo $row_state[0];?></option>
 <?php
 }
 
 }
 else
 {
 echo "ERROR";
 }
 ?>
 </select></td>
 <td>&nbsp;</td> 
 </tr>
 <?php
 }
 }
 ?>
</table>
</form>
</body>




 

how to redirect your website in php

I will show you how to redirect the website from one page to another page.

we can use either action method from the attribute of form tag.

<form action=”premal.php” name=”form”></form>

it will redirect your website to premal.php

redirect_website

another way to redirect the website is with using header() function of PHP.

header()

We have done redirection of website in php

Premal Katigar

84604-57306

premalkatigar2@gmail.com

PHP user defined function

I will show you how to use user defined functions in PHP.

user defined functions are used mostly to decrease the coding load.

Besides the built-in PHP functions, we can create our own functions.

A function is a block of statements that can be used repeatedly in a program.

A function will not execute immediately when a page loads.

A function will be executed by a call to the function.

A user defined function declaration starts with the word “function”:

we create a function named “premal()”. The opening curly brace ( { ) indicates the beginning of the function code and the closing curly brace ( } ) indicates the end of the function. The function outputs “premal katigar!”. To call the function, just write its name:

user_defined_functions

We have done user defined functions.

how to store images in database using PHP

Firstly create your fetching_images.php file.

storing_images_using_php

now create add.php file.

In below code automatically create a new folder named inages in your www directory. all the images which you upload from here will store in that images folder.

we can create images using mkdir() function of PHP.

fetching_images_using_php

now create new file for displaying images named display.php

fetching_images_using_php1

You have successfully done image storing process. enjoy.

any query mail me or whatsapp me anytime.

thank you.

Loops in PHP

FOR Loop:

A FOR loop continues to process a block of code until a statement becomes false, and everything is defined in a single line, making it somewhat different to a WHILE loop. Read about FOR Loops

WHILE Loops:

Basically what a WHILE loop does is evaluate a statement as true or false. If it is true it executes some code and then alters the original statement and starts all over again by re-evaluating it. It continues to loop through the code like this until the statement becomes false

Examples :

for loop

for_loop

while loop

while_loop

 

Learning conditional statements in PHP

Conditionals allow your program to make choices. Following the same sort of boolean logic you just learned about, the computer can only make two choices; true or false. In the case of PHP this is accomplished using IF : ELSE statements. Below is an example of an IF statement that would apply a senior’s discount.

in following statements if $name is premal then all statements inside breckets should be display.

<?php

$name=”premal”;

if($name=”premal”)

{

echo “Premal Katigar”;

}

else

{

echo “Wrong Statement”;

}

?>

File Handling in PHP

Most Important think that is :

you have to configure first ini file :

goto php.ini

file_uploads = On

file upload
file upload

Check if uploaded file is already exist or not

$target_dir = “uploads/”;
$target_file = $target_dir . basename($_FILES[“fileToUpload”][“name”]);

if (file_exists($target_file)) {
echo “Sorry, file already exists.”;
$uploadOk = 0;

 

Restriction for file size

if ($_FILES[“fileToUpload”][“size”] > 500000) {
echo “Sorry, your file is too large.”;
$uploadOk = 0;

Limit File Type :

if($imageFileType != “jpg” && $imageFileType != “png” && $imageFileType != “jpeg”
&& $imageFileType != “gif” ) {
echo “Sorry, only JPG, JPEG, PNG & GIF files are allowed.”;
$uploadOk = 0;

Using Cookies in PHP

A cookie is often used to identify a user. A cookie is a small file that the server embeds on the user’s computer. Each time the same computer requests a page with a browser, it will send the cookie too. With PHP, you can both create and retrieve cookie values.

Now Let’s See how to use Cookies.

A cookie is created with the setcookie() function.

Remember one think we have to use cookie before <html> tag.

SYNTAX :

setcookie(name, value, expire, path, domain, secure, httponly);

cookie
cookie

Above code show how to set cookie.

I have set Cookie for 30 days.

cookie
cookie

 

DELETING COOKIES :

main think is that if you want to remove cookie then you have to set it always before 1 hour ahead.

<?php
// set the expiration date to one hour ago
setcookie(“user”, “”, time() – 3600);
?>
<html>
<body>
<?php
echo “Cookie ‘user’ is deleted.”;
?>

</body>
</html>

 

Any Questions feel free to comment & mail me.