Blogger Plug 'n' Play

NOTICE

Adfly Links not working Find Direct Links HERE
Showing posts with label php. Show all posts

How to build long forms using php in a short cut way

We can build a long form using php's foreach function in the following way. It makes the form more manageable and clean
<form name="myform" method="get" action="business.php" onsubmit="">
<?php

$postvalue=array("Name"=>"0","Email"=>"1","Phone"=>"2");
foreach($postvalue as $key => $value)
{
  echo ''.$key.'<input type="text" id="id'.$value.'" name="name['.$value.']" value=""><div id="err'.$value.'"></div><br>';
}

?>
<input type="submit" onclick="checkValidit()">
</form>
We can add any number of keys and values in array To get the values we can use following code
<?php
session_start();
$value = $_GET["name"];

foreach ($value as $uni) {
    $_SESSION[$uni] = $uni;
}

foreach ($value as $uni) {
    echo $_SESSION[$uni] . "<br>";
}
?>
Learn more »

Get Multiple Url Parameters with Same Name Using PHP

index.php?paraname=VALUE1&paraname=VALUE2&paraname=VALUE3&paraname=VALUE4
Now if we get paraname parameter as follow $val = $_REQUEST['paraname']; // Output only last value VALUE4 we can bind all parameters in an array by doing a change in the form from where the values are coming like as follow

<form action="" method="get">
<input name="paraname[]">
<input name="paraname[]">
<input name="paraname[]">
<input name="paraname[]">
</form>

Then we can request the values as
<php

$val = $_REQUEST['paraname'];


foreach ($val as &$Mvalue) {
     
  echo $Mvalue."<br>"; 
 }
?>
Learn more »

How to disable warnings and notices in php.ini and WAMP

open php.ini Search "error_reporting = E_ALL" and Replace it with "error_reporting = E_ALL & ~E_NOTICE & ~E_WARNING" .After saving restart the WAMP 
Learn more »

PHP get multiple CheckBox value using form



<?php 
 $rtt = "";
    $chk = $_REQUEST['txtOwn'];
     if(empty($chk))
     {
  echo("You do not own anything.");
     }
     else
     {
  $N = count($chk);
  for($i=0; $i < $N; $i++)
  {
   $rtt = $rtt."  ,".$chk[$i];
  }
     } 
  
  echo $rtt;
?>


<form method="get">
 <input type="checkbox" name="txtOwn[]" value="AC" />AC<br />
 <input type="checkbox" name="txtOwn[]" value="Fridge" />Fridge<br />
 <input type="checkbox" name="txtOwn[]" value="TV" />TV<br />
 <input type="checkbox" name="txtOwn[]" value="Mobile" />Mobile<br />
 <input type="checkbox" name="txtOwn[]" value="Car" />Car<br />
 <input type="submit" >
 </form>


Learn more »