Past Paper Code

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

<?

php

$num = 4;

$factorial = 1;

for ($x=$num; $x>=1; $x--)

$factorial = $factorial * $x;

echo "Factorial of $num is $factorial";

?>

<html>

<head>

<title>Factorial Program using loop in PHP</title>

</head>

<body>

<form method="post">

Enter the Number:<br>

<input type="number" name="number" id="number">

<input type="submit" name="submit" value="Submit" />

</form>

<?php

if($_POST){

$fact = 1;

//getting value from input text box 'number'

$number = $_POST['number'];

echo "Factorial of $number:<br><br>";

//start loop

for ($i = 1; $i <= $number; $i++){


$fact = $fact * $i;

echo $fact . "<br>";

?>

</body>

</html>

<html>

<head>

<title>Form Input Data</title>

</head>

<body>

<table border="1">

<tr>

<td align="center">Form Input Data</td>

</tr>

<tr>

<td>

<table>

<form method="post" action="VER2.php">

<tr>

<td>Code</td>

<td><input type="text" name="Code" size="10">

</td>

</tr>
<tr>

<td>Title</td>

<td><input type="text" name="Title" size="128">

</td>

</tr>

<tr>

<td>Alt_Title</td>

<td><input type="text" name="Alt_Title" size="128">

</td>

</tr>

<tr>

<td>Type</td>

<td><input type="text" name="Type" size="10">

</td>

</tr>

<tr>

<td>Synopis</td>

<td><input type="text" name="Synopis" size="128">

</td>

</tr>

<tr>

<td>Num_Eps</td>

<td><input type="int" name="Num_Eps" size="12">

</td>

</tr>

<tr>

<td>Duration</td>
<td><input type="time" name="Duration" size="">

</td>

</tr>

<tr>

<td>Total_Duration</td>

<td><input type="time" name="Total_Duration" size="">

</td>

</tr>

<tr>

<td>Catagory</td>

<td><input type="text" name="Catagory" size="25">

</td>

</tr>

<tr>

<td>Year</td>

<td><input type="year" name="Year" size="4">

</td>

</tr>

<input type="checkbox" name="GenCode[]" value="Action"> Action <br />

<input type="checkbox" name="GenCode[]" value="Comedy"> Comedy <br />

<input type="checkbox" name="GenCode[]" value="Adven"> Adventure <br />

<tr>

<td></td>

<td align="right"><input type="submit"

name="submit" value="Sent"></td>

</tr>

</table>
</td>

</tr>

</table>

</body>

</html>

insert:

<?php

mysql_connect("localhost","root","root");//database connection

mysql_select_db("test");

$Code = $_GET['Code'];

//inserting data order

$order = "INSERT INTO MOVIES

(Code, Title, Alt_Title, Type, Synopsis, Num_Eps, Duration, Total_Duration, Catagory, Year)

VALUES

('" .addslashes( $_POST['Code'] ). "',

'" .addslashes( $_POST['Title'] )."',

'" .addslashes( $_POST['Alt_Title'] )."',

'" .addslashes( $_POST['Type'] )."',

'" .addslashes( $_POST['Synopsis'] )."',

'" .addslashes( $_POST['Num_Eps'] )."',

'" .addslashes( $_POST['Duration'] )."',

'" .addslashes( $_POST['Total_Duration'] )."',

'" .addslashes( $_POST['Catagory'] )."',

'" .addslashes( $_POST['Year'] )."')";


//declare in the order variable

echo "order: $order";

$result = mysql_query($order); //order executes

if($result){

echo("<br>Input data is succeed");

} else{

echo("<br>Input data is fail");

mysql_close($mysql_connect);

$con = mysql_connect("localhost","root","root");

if (!$con)

die('Could not connect: ' . mysql_error());

mysql_select_db("test");

$Code = $_GET['Code'];

if(isset($_POST['GenCode']))

foreach($_POST['GenCode'] as $value) {

$insert="INSERT INTO MOVIEGENRES (MovieCode, GenCode) VALUES ('"


.addslashes( $_POST['Code'] ). "','$value')";

mysql_query($insert);

echo $insert;
echo " ";

mysql_close($con);

?>

You might also like