ก F ก F PHP
HTML Form
ก F ก F PHP
projetcsoft.biz F F ก
Tag Form
Tag input F F F tag form
Tag form ˈ F F F F F F F tag input F
.php.php
ก F F F ก F F .php F
Form .PHP file
projetcsoft.biz F F ก
Tag Form
Attribute ˈ F tag form method, action
Attribute action F ก F F form
file file
Attribute method F ก F F F form ˈ GET
( F address bar F index.php?id=1&name=John )( F address bar F index.php?id=1&name=John )
POST ( F F address bar)
Tag form ˈ F tag <input type=“submit” />
projetcsoft.biz F F ก
Tag Form
<form action= F F ก .php method=GET
POST>
……
……
</form></form>
projetcsoft.biz F F ก
Tag input type submit
Tag input Attribute type ˈ submit ˈ ˁ ก
Attribute value F ˁ
Tag input type submit F F F tag form
F F F ก ˁ submit form F browser ʽ F
ก F Attribute action formก F Attribute action form
projetcsoft.biz F F ก
Tag Form
<form action="html_form_manage.php" method="GET">
<input type="submit" value=" ก " />
</form>
ก F F ก ˁ ก F browser ʽ F
html_form_manage.php ก F Attribute actionhtml_form_manage.php ก F Attribute action
form
projetcsoft.biz F F ก
ก F F F ก submit form
F F F ก submit form F F F
<form action="textbox_input_manage.php"
method="get">
<input type="text" id="textbox1" name="textbox1" />
<input type="submit" value=" ก " /><input type="submit" value=" ก " />
</form>
ก F Tag input Attribute id name
projetcsoft.biz F F ก
ก F F F ก submit form
ก F F ก F F F F F
textbox_input_manage.php F
<?php
$textbox1=$_GET["textbox1"];
echo $textbox1;echo $textbox1;
?>
F ก ก F ก textbox F F
textbox_input_manage.php
projetcsoft.biz F F ก
ก F F F ก submit form
• ก F ก $textbox1=$_GET["textbox1"];
• F F tag input F textbox1 (ก
attribute name attribute id) ก F Fattribute name attribute id) ก F F
$textbox1
• ก F address bar F ก F F GET
F ก F F F tag form attribute action
textbox_input_manage.php?textbox1=PHP
• textbox_input_manage.php ก attribute action
form action="textbox_input_manage.php"
projetcsoft.biz F F ก
ก F F F ก submit form
textbox1 ก กAttribute name id<input type="text"
id="textbox1" name="textbox1" />
textbox_input_manage.php?textbox1=PHP
textbox1=PHP
=PHP กก F F F F F F “PHP” textbox1=PHP กก F F F F F F “PHP” textbox1
กF ก submit
projetcsoft.biz F F ก
ก F F F ก submit form
ก F F ก F F address bar F Attribute Form
method="get" ˈ method="post"
projetcsoft.biz F F ก
ก F F F ก submit form
ก F ก attribute Form ก
method="get" ˈ method="post" F
ˈ F F ก F ก
$textbox1=$_GET["textbox1"]; ˈ
$textbox1=$_POST["textbox1"]; F$textbox1=$_POST["textbox1"]; F
projetcsoft.biz F F ก
ก F F F ก submit form
projetcsoft.biz F F ก
ก Username Password
<form action="check_login.php" method="post">
<table><tr><td align="right">Username:</td>
<td><input type="text" id="username" name="username"
/></td>
</tr><tr><td align="right">Password:</td>
<td><td>
<input type="password" id="password" name="password" />
</td></tr><tr><td align="right"></td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
projetcsoft.biz F F ก
ก Username Password
F check_login.php
<?php
$username=$_POST["username"];
$password=$_POST["password"];
if(($username=="administrator")&&($password=="system"))
{{
echo "Login success";
}
else
{
echo "Login error ! <br />";
echo "<a href="login.php">Click to login agian</a>";
}
?>
projetcsoft.biz F F ก
ก Username Password 2
<?php if($_GET["err"]=="1"){echo "Login error !";} ?>
<form action="check_login2.php" method="post">
<table><tr><td align="right">Username:</td>
<td><input type="text" id="username" name="username"
/></td>
</tr><tr><td align="right">Password:</td>
<td>
<input type="password" id="password" name="password" />
</td></tr><tr><td align="right"></td>
<td><input type="submit" value="Login" /></td>
</tr>
</table>
</form>
projetcsoft.biz F F ก
ก Username Password 2
F check_login2.php
<?php
$username=$_POST["username"];
$password=$_POST["password"];
if(($username=="administrator")&&($password=="system"))
{{
echo "Login success";
}
else
{
echo "<script>location='login2.php?err=1'</script>";
exit();
}
?>
projetcsoft.biz F F ก
ก Username Password 2
ก F F F username password F ก F F ก
echo "<script>location='login2.php?err=1'</script>";
exit();
F browser F login2.php F F FF browser F login2.php F F F
?err=1 F
F ก F login2.php
<?php if($_GET["err"]=="1"){echo "Login error !";} ?>
F F Login error ! ก F F err=1
projetcsoft.biz F F ก
ก F F ก Tag select
<form method="post" action="select_input_manage.php">
<select id="number" name="number" >
<option value="">Please select umber</option>
<option value="1">One</option>
<option value="2">Two</option><option value="2">Two</option>
<option value="3">Three</option>
</select>
<input type="submit" value="OK" />
</form>
projetcsoft.biz F F ก
ก F F ก Tag select
ก F tag select attribute value
Attribute value F ก F F F F ก ก ก
F F F F ก ก Two F
$_POST["number"] F select_input_manage.php
F F ก ˈ 2 F value="2" ก TwoF F ก ˈ 2 F value="2" ก Two
<option value="2">Two</option>
projetcsoft.biz F F ก
ก F F ก Tag select
<?php
$num=$_POST["number"];
if($num=="")
{echo "You have not selected.";}
else if($num=="1")
{echo "You have selected One.";}{echo "You have selected One.";}
else if($num=="2")
{echo "You have selectedTwo.";}
else if($num=="3")
{echo "You have selectedTree.";}
?>
<br />
<a href="select_input_submit.php">Back to last page</a>
projetcsoft.biz F F ก
ก F F ก check box
<form method="post" action="checkbox_manage.php" >
Please select your programing langues skill.<br /><br />
<input type="checkbox" value="C++" id="cpp"
name="cpp" />C++
<input type="checkbox" value="Java" id="java"<input type="checkbox" value="Java" id="java"
name="java" />Java
<input type="checkbox" value="PHP" id="php"
name="php" />PHP
<input type="submit" value="OK" />
</form>
projetcsoft.biz F F ก
ก F F ก check box
F checkbox_manage.php
<?php
echo "You have ";
echo $_POST["cpp"]." ";echo $_POST["cpp"]." ";
echo $_POST["java"]." ";
echo $_POST["PHP"]." ";
echo " skill.";
?>
projetcsoft.biz F F ก
ก F F ก check box
ก code F F F F check box PHP F
F F ?
projetcsoft.biz F F ก
ก ก,
<form method="post" action="calculator_result.php">
<input type="text" id="num1" name="num1" size="3"
/>
<select id="opp" name="opp"><option
value="add">+</option><option value="sub">-value="add">+</option><option value="sub">-
</option></select>
<input type="text" id="num2" name="num2" size="3"
/>
<input type="submit" value="=" size="100"/>
</form>
projetcsoft.biz F F ก
ก ก,
<?php
$num1=$_POST["num1"];
$num2=$_POST["num2"];
if($_POST["opp"]=="add")
{$result=$num1+$num2;{$result=$num1+$num2;
echo $num1."+".$num2." = ".$result;}
else if($_POST["opp"]=="sub")
{$result=$num1-$num2;
echo $num1."-".$num2." = ".$result;
}
?>
projetcsoft.biz F F ก
ก ก, 2
<form method="post" action="calculator_result2.php">
<input type="text" id="num1" name="num1" /><br />
<input type="checkbox" value="add" id="op1"
name="op1" />+<br />
<input type="checkbox" value="sub" id="op2"<input type="checkbox" value="sub" id="op2"
name="op2" />-<br />
<input type="text" id="num2" name="num2" /><br />
<input type="submit" value="=" />
</form>
projetcsoft.biz F F ก
ก ก, 2
<?php
$num1=$_POST["num1"];
$num2=$_POST["num2"];
if($_POST["op1"]=="add")
{ $result=$num1+$num2;
echo $num1."+".$num2."=".$result."<br />";echo $num1."+".$num2."=".$result."<br />";
}
if($_POST["op2"]=="sub")
{ $result=$num1-$num2;
echo $num1."-".$num2."=".$result."<br />";
}
?>
projetcsoft.biz F F ก
ก F F F F ˈ F ก F
<form action="multiply.php" method="get">
<select id="num" name="num">
<option value="2">2</option>
<option value="3">3</option>
</select></select>
<input type="submit" value="show !" /></form>
<table>
projetcsoft.biz F F ก
ก F F F F ˈ F ก F
<table><?php
$num=$_GET["num"];
$count=1;
while($count<=12)
{ $result=$num*$count;
echo "<tr>";echo "<td>".$num."</td>";echo "<tr>";echo "<td>".$num."</td>";
echo "<td>X</td>";
echo "<td>".$count."=</td>";
echo "<td>".$result."</td>";echo "</tr>";
$count++;}
?></table>
source code F ก slice F F
projetcsoft.biz F F ก
Input file
Tag name input
Type file
F ก F tag form input file F tag form F F
attribute enctype="multipart/form-data" tag form F
FF
Tag input attribute id name F F F ก tag
input
projetcsoft.biz F F ก
Input file
<form action="upload_file.php" method="post"
enctype="multipart/form-data" >
upload file(.jpg)
<input type="file" name="file_1" id="file_1" />
<input type="submit" value="upload" /><input type="submit" value="upload" />
</form>
projetcsoft.biz F F ก
Input file
<?php
$file_1=$_FILES["file_1"];
$type = substr($file_1["name"], strpos($file_1["name"],"."),
strlen($file_1["name"])); $type =strtolower($type );
if($type!= ".jpg")
{echo "Please select .jpg file<br />";{echo "Please select .jpg file<br />";
echo "<a href="input_file.php" >Click to upload agian</a>";
} else{
copy($file_1["tmp_name"],"upload_img/upload_img.jpg");
echo "<img src="upload_img/upload_img.jpg" />";
}
?>
projetcsoft.biz F F ก
Input file
$file_1=$_FILES["file_1"];
ก F $file_1 F F input file attribute
id="file_1" name="file_1"
$file_1["name"] return F upload F
$type = substr($file_1["name"],$type = substr($file_1["name"],
strpos($file_1["name"],"."), strlen($file_1["name"])); ก
ก F upload ก F $type
projetcsoft.biz F F ก
Input file
$type F F F ก “.jpg” F F F F
F F link F F upload ก
F F F F F ก “.jpg”
copy($file_1["tmp_name"],"upload_img/upload_img.jpg");
F upload F F folder upload_imgF upload F F folder upload_img
F ˈ upload_img.jpg
projetcsoft.biz F F ก

Session6

  • 1.
    ก F กF PHP HTML Form ก F ก F PHP projetcsoft.biz F F ก
  • 2.
    Tag Form Tag inputF F F tag form Tag form ˈ F F F F F F F tag input F .php.php ก F F F ก F F .php F Form .PHP file projetcsoft.biz F F ก
  • 3.
    Tag Form Attribute ˈF tag form method, action Attribute action F ก F F form file file Attribute method F ก F F F form ˈ GET ( F address bar F index.php?id=1&name=John )( F address bar F index.php?id=1&name=John ) POST ( F F address bar) Tag form ˈ F tag <input type=“submit” /> projetcsoft.biz F F ก
  • 4.
    Tag Form <form action=F F ก .php method=GET POST> …… …… </form></form> projetcsoft.biz F F ก
  • 5.
    Tag input typesubmit Tag input Attribute type ˈ submit ˈ ˁ ก Attribute value F ˁ Tag input type submit F F F tag form F F F ก ˁ submit form F browser ʽ F ก F Attribute action formก F Attribute action form projetcsoft.biz F F ก
  • 6.
    Tag Form <form action="html_form_manage.php"method="GET"> <input type="submit" value=" ก " /> </form> ก F F ก ˁ ก F browser ʽ F html_form_manage.php ก F Attribute actionhtml_form_manage.php ก F Attribute action form projetcsoft.biz F F ก
  • 7.
    ก F FF ก submit form F F F ก submit form F F F <form action="textbox_input_manage.php" method="get"> <input type="text" id="textbox1" name="textbox1" /> <input type="submit" value=" ก " /><input type="submit" value=" ก " /> </form> ก F Tag input Attribute id name projetcsoft.biz F F ก
  • 8.
    ก F FF ก submit form ก F F ก F F F F F textbox_input_manage.php F <?php $textbox1=$_GET["textbox1"]; echo $textbox1;echo $textbox1; ?> F ก ก F ก textbox F F textbox_input_manage.php projetcsoft.biz F F ก
  • 9.
    ก F FF ก submit form • ก F ก $textbox1=$_GET["textbox1"]; • F F tag input F textbox1 (ก attribute name attribute id) ก F Fattribute name attribute id) ก F F $textbox1 • ก F address bar F ก F F GET F ก F F F tag form attribute action textbox_input_manage.php?textbox1=PHP • textbox_input_manage.php ก attribute action form action="textbox_input_manage.php" projetcsoft.biz F F ก
  • 10.
    ก F FF ก submit form textbox1 ก กAttribute name id<input type="text" id="textbox1" name="textbox1" /> textbox_input_manage.php?textbox1=PHP textbox1=PHP =PHP กก F F F F F F “PHP” textbox1=PHP กก F F F F F F “PHP” textbox1 กF ก submit projetcsoft.biz F F ก
  • 11.
    ก F FF ก submit form ก F F ก F F address bar F Attribute Form method="get" ˈ method="post" projetcsoft.biz F F ก
  • 12.
    ก F FF ก submit form ก F ก attribute Form ก method="get" ˈ method="post" F ˈ F F ก F ก $textbox1=$_GET["textbox1"]; ˈ $textbox1=$_POST["textbox1"]; F$textbox1=$_POST["textbox1"]; F projetcsoft.biz F F ก
  • 13.
    ก F FF ก submit form projetcsoft.biz F F ก
  • 14.
    ก Username Password <formaction="check_login.php" method="post"> <table><tr><td align="right">Username:</td> <td><input type="text" id="username" name="username" /></td> </tr><tr><td align="right">Password:</td> <td><td> <input type="password" id="password" name="password" /> </td></tr><tr><td align="right"></td> <td><input type="submit" value="Login" /></td> </tr> </table> </form> projetcsoft.biz F F ก
  • 15.
    ก Username Password Fcheck_login.php <?php $username=$_POST["username"]; $password=$_POST["password"]; if(($username=="administrator")&&($password=="system")) {{ echo "Login success"; } else { echo "Login error ! <br />"; echo "<a href="login.php">Click to login agian</a>"; } ?> projetcsoft.biz F F ก
  • 16.
    ก Username Password2 <?php if($_GET["err"]=="1"){echo "Login error !";} ?> <form action="check_login2.php" method="post"> <table><tr><td align="right">Username:</td> <td><input type="text" id="username" name="username" /></td> </tr><tr><td align="right">Password:</td> <td> <input type="password" id="password" name="password" /> </td></tr><tr><td align="right"></td> <td><input type="submit" value="Login" /></td> </tr> </table> </form> projetcsoft.biz F F ก
  • 17.
    ก Username Password2 F check_login2.php <?php $username=$_POST["username"]; $password=$_POST["password"]; if(($username=="administrator")&&($password=="system")) {{ echo "Login success"; } else { echo "<script>location='login2.php?err=1'</script>"; exit(); } ?> projetcsoft.biz F F ก
  • 18.
    ก Username Password2 ก F F F username password F ก F F ก echo "<script>location='login2.php?err=1'</script>"; exit(); F browser F login2.php F F FF browser F login2.php F F F ?err=1 F F ก F login2.php <?php if($_GET["err"]=="1"){echo "Login error !";} ?> F F Login error ! ก F F err=1 projetcsoft.biz F F ก
  • 19.
    ก F Fก Tag select <form method="post" action="select_input_manage.php"> <select id="number" name="number" > <option value="">Please select umber</option> <option value="1">One</option> <option value="2">Two</option><option value="2">Two</option> <option value="3">Three</option> </select> <input type="submit" value="OK" /> </form> projetcsoft.biz F F ก
  • 20.
    ก F Fก Tag select ก F tag select attribute value Attribute value F ก F F F F ก ก ก F F F F ก ก Two F $_POST["number"] F select_input_manage.php F F ก ˈ 2 F value="2" ก TwoF F ก ˈ 2 F value="2" ก Two <option value="2">Two</option> projetcsoft.biz F F ก
  • 21.
    ก F Fก Tag select <?php $num=$_POST["number"]; if($num=="") {echo "You have not selected.";} else if($num=="1") {echo "You have selected One.";}{echo "You have selected One.";} else if($num=="2") {echo "You have selectedTwo.";} else if($num=="3") {echo "You have selectedTree.";} ?> <br /> <a href="select_input_submit.php">Back to last page</a> projetcsoft.biz F F ก
  • 22.
    ก F Fก check box <form method="post" action="checkbox_manage.php" > Please select your programing langues skill.<br /><br /> <input type="checkbox" value="C++" id="cpp" name="cpp" />C++ <input type="checkbox" value="Java" id="java"<input type="checkbox" value="Java" id="java" name="java" />Java <input type="checkbox" value="PHP" id="php" name="php" />PHP <input type="submit" value="OK" /> </form> projetcsoft.biz F F ก
  • 23.
    ก F Fก check box F checkbox_manage.php <?php echo "You have "; echo $_POST["cpp"]." ";echo $_POST["cpp"]." "; echo $_POST["java"]." "; echo $_POST["PHP"]." "; echo " skill."; ?> projetcsoft.biz F F ก
  • 24.
    ก F Fก check box ก code F F F F check box PHP F F F ? projetcsoft.biz F F ก
  • 25.
    ก ก, <form method="post"action="calculator_result.php"> <input type="text" id="num1" name="num1" size="3" /> <select id="opp" name="opp"><option value="add">+</option><option value="sub">-value="add">+</option><option value="sub">- </option></select> <input type="text" id="num2" name="num2" size="3" /> <input type="submit" value="=" size="100"/> </form> projetcsoft.biz F F ก
  • 26.
    ก ก, <?php $num1=$_POST["num1"]; $num2=$_POST["num2"]; if($_POST["opp"]=="add") {$result=$num1+$num2;{$result=$num1+$num2; echo $num1."+".$num2."= ".$result;} else if($_POST["opp"]=="sub") {$result=$num1-$num2; echo $num1."-".$num2." = ".$result; } ?> projetcsoft.biz F F ก
  • 27.
    ก ก, 2 <formmethod="post" action="calculator_result2.php"> <input type="text" id="num1" name="num1" /><br /> <input type="checkbox" value="add" id="op1" name="op1" />+<br /> <input type="checkbox" value="sub" id="op2"<input type="checkbox" value="sub" id="op2" name="op2" />-<br /> <input type="text" id="num2" name="num2" /><br /> <input type="submit" value="=" /> </form> projetcsoft.biz F F ก
  • 28.
    ก ก, 2 <?php $num1=$_POST["num1"]; $num2=$_POST["num2"]; if($_POST["op1"]=="add") {$result=$num1+$num2; echo $num1."+".$num2."=".$result."<br />";echo $num1."+".$num2."=".$result."<br />"; } if($_POST["op2"]=="sub") { $result=$num1-$num2; echo $num1."-".$num2."=".$result."<br />"; } ?> projetcsoft.biz F F ก
  • 29.
    ก F FF F ˈ F ก F <form action="multiply.php" method="get"> <select id="num" name="num"> <option value="2">2</option> <option value="3">3</option> </select></select> <input type="submit" value="show !" /></form> <table> projetcsoft.biz F F ก
  • 30.
    ก F FF F ˈ F ก F <table><?php $num=$_GET["num"]; $count=1; while($count<=12) { $result=$num*$count; echo "<tr>";echo "<td>".$num."</td>";echo "<tr>";echo "<td>".$num."</td>"; echo "<td>X</td>"; echo "<td>".$count."=</td>"; echo "<td>".$result."</td>";echo "</tr>"; $count++;} ?></table> source code F ก slice F F projetcsoft.biz F F ก
  • 31.
    Input file Tag nameinput Type file F ก F tag form input file F tag form F F attribute enctype="multipart/form-data" tag form F FF Tag input attribute id name F F F ก tag input projetcsoft.biz F F ก
  • 32.
    Input file <form action="upload_file.php"method="post" enctype="multipart/form-data" > upload file(.jpg) <input type="file" name="file_1" id="file_1" /> <input type="submit" value="upload" /><input type="submit" value="upload" /> </form> projetcsoft.biz F F ก
  • 33.
    Input file <?php $file_1=$_FILES["file_1"]; $type =substr($file_1["name"], strpos($file_1["name"],"."), strlen($file_1["name"])); $type =strtolower($type ); if($type!= ".jpg") {echo "Please select .jpg file<br />";{echo "Please select .jpg file<br />"; echo "<a href="input_file.php" >Click to upload agian</a>"; } else{ copy($file_1["tmp_name"],"upload_img/upload_img.jpg"); echo "<img src="upload_img/upload_img.jpg" />"; } ?> projetcsoft.biz F F ก
  • 34.
    Input file $file_1=$_FILES["file_1"]; ก F$file_1 F F input file attribute id="file_1" name="file_1" $file_1["name"] return F upload F $type = substr($file_1["name"],$type = substr($file_1["name"], strpos($file_1["name"],"."), strlen($file_1["name"])); ก ก F upload ก F $type projetcsoft.biz F F ก
  • 35.
    Input file $type FF F ก “.jpg” F F F F F F link F F upload ก F F F F F ก “.jpg” copy($file_1["tmp_name"],"upload_img/upload_img.jpg"); F upload F F folder upload_imgF upload F F folder upload_img F ˈ upload_img.jpg projetcsoft.biz F F ก