Sie sind auf Seite 1von 9

1) Write a PHP script to find sum of given two numbers from text box.

= <?php
extract($_POST);
//do addition and store the result in $res
if(isset($add))
{
$res=$fnum+$snum;
}

?>

Output:

2) Write a PHP script to find max value in given three numbers from text box.

3) <?php
4) $num1=20;
5) $num2=15;
6) $num3=22;
7) if($num1>$num2 && $num1>$num3){
8) echo $num1;
9) }
10) else{
11) if($num2>$num1 && $num2>$num3){
12) echo $num2;
13) }
14) else
15) echo $num3;
16) }
17)
18) ?>

3) Write a PHP script to find GCD/HCF in given two numbers from text box

<?php

function gcd($a, $b)

// Everything divides 0

if ($a == 0)

return $b;
if ($b == 0)

return $a;

// base case

if($a == $b)

return $a ;

// a is greater

if($a > $b)

return gcd( $a-$b , $b ) ;

return gcd( $a , $b-$a ) ;

4) Write a PHP script to find LCM in given two numbers from text box.

<?php
  $num1=3;
  $num2=4;
  $max=($num1>$num2) ? $num1 : $num2;
    while(1)
    {
      if($max%$num1==0 && $max%$num2==0)
        {
          echo "LCM of " .$num1. " and " .$num2. " is: ".$max;
          break;
        }
    $max=$max+1;
    }
?>

5) Write a PHP script to check that given value is prime or not input from text box.

<?php
function IsPrime($n)
{
for($x=2; $x<$n; $x++)
{
if($n %$x ==0)
{
return 0;
}
}
return 1;
}
$a = IsPrime(3);
if ($a==0)
echo 'This is not a Prime Number.....'."\n";
else
echo 'This is a Prime Number..'."\n";
?>
6) Write a PHP script to print N natural numbers. N input from text box

<?php
function sum_of_nums($n_val, $k_val)
{
   $tot_sum = ($n_val * ($n_val + 1)) / 2;
   $pow_val = $k_val;
   while ($pow_val <= $n_val)
   {
      $tot_sum -= $pow_val;
      $pow_val *= $k_val;
   }
   return $tot_sum;
}
$n_val = 20; $k_val = 3;
print_r("The sum of fist 20 natural numbers that are not powers
of 3 is ");
echo sum_of_nums($n_val, $k_val);
?>

Output
The sum of fist 20 natural numbers that are not powers of 3 is
198

7) Write a PHP script to print N fibbonacci series numbers. N input from text box.

<?php

// PHP code to get the Fibonacci series

function Fibonacci($n){

$num1 = 0;

$num2 = 1;

$counter = 0;

while ($counter < $n){

echo ' '.$num1;


$num3 = $num2 + $num1;

$num1 = $num2;

$num2 = $num3;

$counter = $counter + 1;

// Driver Code

$n = 10;

Fibonacci($n);

?>

Output:
0 1 1 2 3 5 8 13 21 34

8) Write a PHP script to print N prime numbers. N input from text box.

1. <?php  
2. $count = 0;  
3. $num = 2;  
4. while ($count < 15 )  
5. {  
6. $div_count=0;  
7. for ( $i=1; $i<=$num; $i++)  
8. {  
9. if (($num%$i)==0)  
10. {  
11. $div_count++;  
12. }  
13. }  
14. if ($div_count<3)  
15. {  
16. echo $num." , ";  
17. $count=$count+1;  
18. }  
19. $num=$num+1;  
20. }  
21. ?> 

OUTPUT

2,3,5,7,11,13,17,19,23,29,31,37,41
9) Write a PHP script to Sort an Array. Array values input from text boxes.?

<?php
$numbers = array(4, 6, 2, 22, 11);
rsort($numbers);
?>

OUTPUT:

22
11
6
4
2

10) Write a PHP script to Search a value in an Array. Array values input from text
boxes?
<?php

// PHP function to illustrate the use of array_search()

function Search($value, $array)

    return(array_search($value, $array));

$array = array("ram", "aakash", "saran", "mohan", "saran");

$value = "saran";

print_r(Search($value, $array));

?>

11) Write a PHP script to search a given word in given Sentence. Input from text boxes.

<?php

$text = "Hello World!";

if ($text contains "World") {


echo "True";
}

?>

12) Write a PHP script to print data from given file. File name input from file control.
1. ?php  
2. $target_path = "e:/";  
3. $target_path = $target_path.basename( $_FILES['fileToUpload']['name']);   
4.   
5. if(move_uploaded_file($_FILES['fileToUpload']['tmp_name'], $target_path)) {  
6.     echo "File uploaded successfully!";  
7. } else{  
8.     echo "Sorry, file not uploaded, please try again!";  
9. }  
10. ?>  

13) Write a PHP script to check that given username and password is valid or not using database.

if(isset($_POST["name"], $_POST["password"]))
{

$name = $_POST["name"];
$password = $_POST["password"];

$result1 = mysql_query("SELECT password FROM Users WHERE username = '".$name."'");


$result2 = mysql_query("SELECT username FROM Users WHERE password = '".$password."'");

if($name == $result2 && $password == $result1)


{
$_SESSION["logged_in"] = true;
$_SESSION["naam"] = $name;
}
else
{
echo'The username or password are incorrect!';
}
}

14) Write -a PHP scripts to develop login module using database.?

<form method="post" action="" name="signup-form">


    <div class="form-element">
        <label>Username</label>
        <input type="text" name="username" pattern="[a-zA-Z0-9]+"
required />
    </div>
    <div class="form-element">
        <label>Email</label>
        <input type="email" name="email" required />
    </div>
    <div class="form-element">
        <label>Password</label>
        <input type="password" name="password" required />
    </div>
    <button type="submit" name="register"
value="register">Register</button>
</form>

15) Write a PEEP scripts to upload given image in server side folder.

<?php
$target_dir = "uploads/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
  $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
  if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
  } else {
    echo "File is not an image.";
    $uploadOk = 0;
  }
}
?>

16) Write a PHP script to upload given image in table database

<?php

error_reporting(0);

?>

<?php

$msg = "";

// If upload button is clicked ...

if (isset($_POST['upload'])) {

$filename = $_FILES["uploadfile"]["name"];

$tempname = $_FILES["uploadfile"]["tmp_name"];

$folder = "image/".$filename;

$db = mysqli_connect("localhost", "root", "", "photos");

// Get all the submitted data from the form

$sql = "INSERT INTO image (filename) VALUES ('$filename')";

// Execute query

mysqli_query($db, $sql);

// Now let's move the uploaded image into the folder: image
if (move_uploaded_file($tempname, $folder)) {

$msg = "Image uploaded successfully";

}else{

$msg = "Failed to upload image";

$result = mysqli_query($db, "SELECT * FROM image");

?>

17) write a php script to send sms using way2sms Freewebservice?

<?
php
if(isset($_POST["btn_submit"])){
require_once('classSms.php');
$ob = new Sms($_POST["txt_username"],$_POST["txt_password"]);
$message=$ob->sendSMSToMany($_POST["txt_mobno"],$_POST["ta_msg"]);
echo "<div style=\"color:red;\">$message</div>";
}
?>
<div>Note:for groupSms seperate each number using ;(semicolon)</div>
<form method="post" name="InstantSMS" style="" action="sendsms.php">
<table>
<tr>
<td>Username : </td>
<td><input type="text" name="txt_username"/></td>
</tr>
<tr>
<td>Password : </ts>
<td><input type="password" name="txt_password"/></td>
</tr>
<tr>
<td>Phone Numbers : </td>
<td><input type="text" name="txt_mobno"/></td>
</tr>
<tr>
<td>Message : </td>
<td><textarea name="ta_msg"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" value="send sms"
name="btn_submit"/></td>
</tr>
</table>
</form>

19) Write a PHP script to encode and decode given text .Text input from textbox.
<!DOCTYPE html>

<html>

<body>

<?php

$text = "\xE0";

echo utf8_encode($text);

?>

</body>

</html>

Minor Project: Basic online exam system using database..

Das könnte Ihnen auch gefallen