페이지

레이블이 php인 게시물을 표시합니다. 모든 게시물 표시
레이블이 php인 게시물을 표시합니다. 모든 게시물 표시

2012년 9월 9일 일요일

php - go to other page



<!-- go to other page by button -->
<input type="button" value="go list" onClick="location.href='simple_list.php'">

<!-- go to other page by hypertext -->
<td colspan="4" align="center"><a href="simple_insert.html"> insert </a> </td>

php - script alert, history.back


<?
if(!$id){
echo " <script> alert(' please, input id'); history.back();</script>";
exit;
}
?>

php - form



<form name="frm" method="post" action="simple_delete.php'">
<input type="submit" value="delete">
</form>


<form name="frm" method="post" action="simple_delete.php?no=<?=$_GET[no]?>'">
<input type="submit" value="delete">
</form>

<form name="frm" method="post" action="simple_pwd_chk.php?no=<?=$_GET[no]?>'">
<input type="text" name="inputPwd">
<input type="submit" value="check password">
</form>

php - DB


<?
$sql = mysql_connect("localhost","user","password") or die("sql not connected". mysql_error());
mysql_select_db("db_name");
$qry = "select * from table_name";
$result = mysql_query($qry);
{
while($rows=mysql_fetch_array($result)){
echo $rows[id];
echo $rows[name];
echo $rows[phone];
}
}
{
$db_pwd = mysql_result($result,0,0); //mysql_fetch_array 보다 빠르다}
}


mysql_free_result($result);
mysql_close($sql);
?>

2012년 8월 19일 일요일

form send

<?
    $br = "<br>";
?>

<html>
<head><title>환경변수</title></head>
<body>
<?
    if($your_name && $your_phone){
        echo "{$your_name}님의 전화번호는 {$your_phone}입니다";
    }
   
?>
<!--
<form name = form action = "ex.php" method=post>
    post: 보내는 방식.보안에 좋음, get:보안에 않좋음.
-->

<!-- <form name = form action = "<?=$_SERVER[PHP_SELF]?>" method=post> -->
<form name = form method=post action = "ex2.html">
    <font face=굴림 size=2>
    이름 : <input type = "text" name = "your_name"> <br>
    전화 : <input type = "text" name = "your_phone"> <br>
    <input type="submit" value="send">
    </font>   
</form>


</body>
</html>


환경변수
PHP_SELF : 현 파일이름.
DOCUMENT_ROOT: 현파일의 절대경로
REMOTE_ADDR : 사용자의 IP주소

환경변수 사용시 $_SERVER 로 감싼다.
$_SERVER[REMOTE_ADDR]

php test

<?
    $br = "<br>";
?>

<?
    $file = "fopen_test.txt";
    if(file_exists($file)==false){
        echo "file not found:".$file;
        return;
    }
   
    $fp = fopen($file,r);
    if(!$fp){
        echo "failed to open";
       
    } else {
        $contents = fread($fp,filesize($file));
        echo $contents;
    }
    fclose($fp);
    echo $br;
    echo "read ok";



   
    $fp = fopen($file,a);
    if(!$fp){
        echo "failed to open";
    }else {
        $str = "append string ok추가";
        fwrite($fp,$str.$br);
        fclose($fp);
    }
    echo $br."ok! insert";   
   
?>