46일차_PHP

서창민·2023년 5월 16일
0

HTML

목록 보기
17/18
post-thumbnail

23.05.16 화 46일차

PHP, HTML 활용

  • 테이블 만들기

정보처리기사 예제 문제를 활용하여 테이블 만들 후 페이지 구현하기.


phpmyadmin 진입하여 PPK 데이터베이스에 examtbl 테이블을 구현

* DB에 테이블 작성

Create table examtbl (
 sno varchar(10)  not  null primary key ,
 sname varchar(20),
 kor  int,
 eng  int,
 math int,
 hist int
) ;

insert into examtbl values('10101','김학생', 75, 85, 90, 60);
insert into examtbl values('10102','이학생', 70, 75, 70, 60);
insert into examtbl values('10103','박학생', 70, 85, 80, 75);
insert into examtbl values('10201','조학생', 90, 85, 100, 50);
insert into examtbl values('10202','황학생', 65, 65, 60, 70);
insert into examtbl values('10203','임학생', 45, 55, 50, 55);
insert into examtbl values('10304','천학생', 70, 75, 85, 80);
insert into examtbl values('10305','남학생', 100, 85, 90, 90);
insert into examtbl values('10306','여학생', 80, 95, 90, 85);
insert into examtbl values('10307','노학생', 35, 55, 70, 55);

// 테이블 내용 확인
select *  from examtbl;

HTML 파일로 화면을 구현

* 학생 성적처리저장 테이블 구현된 화면 작성

<html>
<head> </head>
<style>
    h2{
        color:blueviolet
    }
    table{
        width : 300px;
        height : 480px;
        border-color:red;
        background-color:lightsalmon;
    }
    td{
        color:blue
    }
    tr{
        font-size: 30px;
    }
</style>
<body>
<div align="center">
<br><br><br>
    <h2>학생 성적 처리 저장하기</h2>
        <table border="3">
            <!-- examtbl 테이블 데이터 -->
            <tr>
                <td>학번</td> <td><input type="text" name=sno></td>
            </tr>
            <tr>
                <td>이름</td> <td><input type="text" name=name></td>
            </tr>
            <tr>
                <td>국어</td> <td><input type="number" name=kor></td>
            </tr>
            <tr>
                <td>영어</td> <td><input type="number" name=eng></td>
            </tr>
            <tr>
                <td>수학</td> <td><input type="number" name=math></td>
            </tr>
            <tr>
                <td>역사</td> <td><input type="number" name=hist></td>
            </tr>
            <!-- 버튼 -->
            <tr>
                <td align="center" colspan="2"><input type="submit" value="저장하기"></td>
            </tr>
        </table>
</div>
</body>
</html>

학생 성적 처리 프로그램을 위한 PHP 화면 구현

* PHP로 폼 이동 가능한 링크 진입 화면 

<html>
<head> </head>
<body>
<div align="center">
<br><br><br>
    <h2>학생 성적 처리 프로그램</h2>
    <br><br><br>
        <h3>
            <a href=form0516.php>학생성적 저장하기</a><br><br>
            <a href=list0516.php>학생성적 저장하기</a><br><br>
        </h3>
        
</div>
</body>
</html>

학생 테이블 데이터 저장하기 화면

<?php
    $sno = $_REQUEST['sno'];
    $sname = $_REQUEST['sname'];
    $kor = $_REQUEST['kor'];
    $eng = $_REQUEST['eng'];
    $math = $_REQUEST['math'];
    $hist = $_REQUEST['hist'];

include "fotable0516.php";

include "dbconn0516.php";


$sql = "INSERT INTO examtbl (sno, sname, kor, eng, math, hist)";
$sql = $sql. " VALUES ( '". $sno . "',"; 
$sql = $sql. " '". $sname . "',";
$sql = $sql. " '". $kor . "',";
$sql = $sql. " '". $eng . "',";
$sql = $sql. " '". $math . "',";
$sql = $sql. " '". $hist . "')";

if ($conn->query($sql) === TRUE) {
    echo "New record created successfully";
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }
  
  $conn->close();
?>

profile
Back-end Developer Preparation Students

0개의 댓글