728x90
728x90
BIG
autoset 접속
테이블 만들기
테이블만든건
https://hyejin283.tistory.com/224
[PHP] mysql 디비 넣어보기
오토셋을 킨다 root / autoset 이런화면이 뜰것이다. 데이터베이스명을 넣고 만들기 누르면 만들어짐 sql 문 들어가서 만들어준다. Create table marja ( name varchar(10) , age int ); 그리고 데이터를 넣어줌 vsco
hyejin283.tistory.com
입력란 만들기
저는 form.php로 만들었습니다.
<form align="center" action="form_ok.php" alt="폼오케" method=get> //get 방식으로 액션을 넘어가게 지정했음
학번: <input type ="text" name = "sno" ><br> // 네임을 꼭 지정해줘야 리퀘스트로 넘길때 좋음
이름:<input type ="text" name = "sname"><br>
국어:<input type ="text" name = "kor" ><br>
영어:<input type ="text" name = "eng" ><br>
수학:<input type ="text" name = "math"><br>
역사:<input type ="text" name = "hist"><br>
<input type ="submit" value = "저장하기"> //submit이아닌 버튼으로 만들수 있음
</form>
데이터넣기
<div align = "center">
<? include ("dbconn.php");?> //dbconn을 포함하고있다
<?php
$sno=$_REQUEST['sno']; // 여기서 아까 폼태그 이름을 적어준다
$sname=$_REQUEST['sname'];
$kor=$_REQUEST['kor'];
$eng=$_REQUEST['eng'];
$math=$_REQUEST['math'];
$hist=$_REQUEST['hist'];
$sql = "INSERT INTO examtbl (sno, sname, kor, eng, math, hist)
VALUES ('$sno', '$sname', '$kor', '$eng', '$math', '$hist')";
if ($conn->query($sql) === TRUE) {
echo "저장완료";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
header('Location:list.php'); //잘 넘어갔을때 이화면을 넘겨줄거야
?>
</div>
삭제문 만들기
<? include("dbconn.php"); ?>
<?php
$sno=$_REQUEST['sno'];
$sql = "delete from examtbl where sno = '$sno'";
if ($conn->query($sql) === TRUE) {
echo "저장완료";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
// 커넥션에서 sql변수로 쿼리를 실행 == true가 값이 들어가있는 것이니까(람다표현식)
// === 값도 같고, 형식도 같음 oop
header('Location:list.php');
$conn.close();
?>
합계문만들기
<div align ="center">
<br><br>
<h1>학생 성적 목록 </h1>
<? include("dbconn.php"); ?>
<!-- 불러오기-->
<?php
/*
$servername = "localhost";
$username = "root";
$password = "autoset";
$dbname = "jungbo";
*/
// Create connection
//$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
//if ($conn->connect_error) {
// die("Connection failed: " . $conn->connect_error);
//}
$sql = "SELECT sno, sname, kor, eng, math, hist,kor+eng+math+hist as summ, (kor+eng+math+hist)/4 as avg FROM examtbl";
$result = $conn->query($sql);
// $avgK = $row["sumK"] / 4 ;평균
if ($result->num_rows > 0) {
// output data of each row
?>
<table border=1 width=75%>
<tr>
<th>번호</th>
<th>이름</th>
<th>국어</th>
<th>영어</th>
<th>수학</th>
<th>역사</th>
<th>합계</th>
<th>평균</th></tr>
<?
while($row = $result->fetch_assoc()) {
?>
<tr>
<td><?=$row["sno"]?></td>
<td>
<a href=delete.php?sno=<?=$row['sno']?>>
<?=$row["sname"]?>
</a>
</td>
<td><?=$row["kor"]?></td>
<td><?=$row["eng"]?></td>
<td><?=$row["math"]?></td>
<td><?=$row["hist"]?></td>
<td><?=$row["summ"]?></td>
<td><?=$row["avg"]?></td>
// <td> <?=$avgK?></td>
</tr>
<?
}
?>
</table>
<?
}else {
echo "0 results";
}
$conn->close();
?>
</div>
728x90
반응형
BIG
'🍓PHP' 카테고리의 다른 글
[PHP/VSCode] 자동정렬 (0) | 2022.12.01 |
---|---|
[PHP] 게시판 수정하기 (0) | 2022.11.30 |
[PHP] mysql 디비 넣어보기 (0) | 2022.11.30 |
[PHP]FOR문으로 테이블만들어보기! (0) | 2022.11.30 |
[PHP] for문 (0) | 2022.11.30 |
댓글