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

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>




 

select option in php using database

I will show you how to add data into select option by fetching data from database. its quite simple. select option is mostly used for registrations & other major activities & forms. select option is useful.

create database named premal. add 1 table named location_country with 2 fields. 1 is for id autoincrement & name.

premal katigar

After that some data into database.

Now get following Code.

<?php
$con=mysql_connect("localhost","root");
mysql_select_db("premal",$con);
?>
<select name="location" id="location">
$query="select name from location_country";
 $result=mysql_query($query);
 if($result)
 {
 ?>
 <option value="NULL">SELECT</option>
 <?php
 while($row=mysql_fetch_array($result))
 {
 ?>
 <option value="<?php $row[0] ?>"><?php echo $row[0] ?></option>
 <?php
 }
 }
 ?> 


</select>

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

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.

formatting using PHP

So you’ve gone though some of the tutorial, and you can make some nifty things in PHP. But the problem is, they all look like plain text. How do you jazz them up?

Formatting with PHP actually isn’t done with PHP, it’s done with HTML. You can do this in two ways. You can add the HTML inside of the PHP… or you can add the PHP inside of the HTML. Either way, make sure your file is saved as a .php or another file type that is allowed to execute PHP on your server.

HTML inside PHP

<?php

echo “<font color=red>Premal Katigar</font>”;

?>

PHP inside HTML

<font color=”red”>

<?php echo “Premal Katigar”; ?>

</font>

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”;

}

?>