제 나름대로 예제를 만들어서 php 웹을 만들고 있습니다. mysql 결합해서요.
불러오기는 되는데 이상한 오류가 나옵니다.
변수가 문제는 아닌거같은데 말이죠. DB에서 읽어오는건 됩니다.

입력하기 버튼이랑 삭제 버튼이 작동을 안하고 삭제 버튼 누르면 아래와 같은 오류가 발생합니다.
Notice: Undefined variable: num in /home1/skte12/public_html/score_delete.php on line 8
Warning: mysqli_query() expects parameter 1 to be mysqli, string given in /home1/skte12/public_html/score_delete.php on line 9
아래는 php 문서 전문입니다.
// score_list.php
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>성적 관리 프로그램</title>
</head>
<body>
<h3>1) 성적 입력 하기</h3>
<form action="score_list.php?mode=insert" method='post'>
<table width="850" border="1" cellpadding="5">
<tr><td> 이름 : <input type="text" size="6" name="name">
과목1 : <input type="text" size="3" name="sub1">
과목2 : <input type="text" size="3" name="sub2">
과목3 : <input type="text" size="3" name="sub3">
과목4 : <input type="text" size="3" name="sub4">
과목5 : <input type="text" size="3" name="sub5">
</td>
<td align="center">
<input type="submit" value="입력하기">
</td>
</tr>
</table>
</form>
<?
error_reporting(E_ALL);
ini_set("display_errors", 1);
$connect = mysqli_connect("localhost","skte12","jack0325", "skte12"); // DB 연결
$mode = "";
if ($mode == "insert") // 데이터 입력 모드
{
$sum = $sub1 + $sub2 + $sub3 + $sub4 + $sub5; // 합계 구하기
$avg = $sum/5; // 평균 구하기
$sql = "INSERT INTO stud_score (name, sub1, sub2, sub3, sub4, sub5, sum, avg) VALUES";
$sql .= "('$name', $sub1, $sub2, $sub3, $sub4, $sub4, $sum, $avg)";
$result = mysqli_query($sql, $connect);
}
?>
<p>
<h3>2) 성적 출력 하기</h3>
<p><a href ="score_list.php?mode=big_first">[성적순 정렬]</a>
<a href ="score_list.php?mode=small_first">[성적역순 정렬]</a></p>
</p>
<!-- 제목 표시 시작 -->
<table width="720" border="1" cellpadding="5">
<tr align="center" bgcolor="#eeeeee">
<td>번호</td>
<td>이름</td>
<td>과목1</td>
<td>과목2</td>
<td>과목3</td>
<td>과목4</td>
<td>과목5</td>
<td>합계</td>
<td>평균</td>
<td>삭제</td>
</tr>
<!-- 제목 표시 끝 -->
<?php
if ($mode == "big_first") // 성적순 정렬(내림차순)
$sql = "SELECT * from stud_score order by sum desc";
else if ($mode == "small_first") // 성적순 정렬(오름차순)
$sql = "SELECT * from stud_score order by sum";
else
$sql = "SELECT * from stud_score";
$result = mysqli_query($connect, $sql);
$count = 1;
while ($row = mysqli_fetch_array($result)) {
$avg = round($row[avg], 1);
$num = $row[num];
echo "<tr align='center'>";
echo "<td> $count </td>";
echo "<td> $row[name] </td>";
echo "<td> $row[sub1] </td>";
echo "<td> $row[sub2] </td>";
echo "<td> $row[sub3] </td>";
echo "<td> $row[sub4] </td>";
echo "<td> $row[sub5] </td>";
echo "<td> $row[sum] </td>";
echo "<td> $avg </td>";
echo "<td> <a href='score_delete.php?num=$num'>[삭제]</a></td>";
echo "</tr>";
$count++;
}
mysqli_close($connect);
?>
</table>
</body>
</html>
// score_delete.php
<?
error_reporting(E_ALL);
ini_set("display_errors", 1);
$connect = mysqli_connect("localhost", "skte12", "jack0325", "skte12");
// 필드 num이 $num 값을 가지는 레코드 삭제
$sql = "DELETE FROM stud_score where num=$num";
mysqli_query($sql, $connect);
mysqli_close($connect);
// score_list.php 로 돌아감
//Header("Location:score_list.php");
?>
mysql 관련 함수는 나중에 없어진다라는 오류가 나오면서 mysqli 관련 함수 추천해줘서 수정하고 있습니다.
책에 안 나와서 해맸네요. 진심으로 감사합니다.
물론 $sub4, $sub4를 $sub4, $sub5로 수정해서 해본겁니다.
$name = $_POST['name'];
$sub1 = $_POST['sub1'];
$sub2 = $_POST['sub2'];
$sub3 = $_POST['sub3'];
$sub4 = $_POST['sub4'];
$sub5 = $_POST['sub5'];
를 추가하니 데이터가 들어가네요.
Notice: Undefined index: mode in /home1/skte12/public_html/score_list.php on line 37Notice: Undefined index: name in /home1/skte12/public_html/score_list.php on line 38Notice: Undefined index: sub1 in /home1/skte12/public_html/score_list.php on line 39Notice: Undefined index: sub2 in /home1/skte12/public_html/score_list.php on line 40Notice: Undefined index: sub3 in /home1/skte12/public_html/score_list.php on line 41Notice: Undefined index: sub4 in /home1/skte12/public_html/score_list.php on line 42Notice: Undefined index: sub5 in /home1/skte12/public_html/score_list.php on line 43
이게 남아있다는게 흠이지만 오류는 아니라서 넘겨야될 듯하네요 ㅠ
Notice: Undefined variable: mode in /home1/skte12/public_html/score_list.php on line 31
내림차순 오름차순도 똑같은 오류요.
Notice: Undefined variable: mode in /home1/skte12/public_html/score_list.php on line 65Notice: Undefined variable: mode in /home1/skte12/public_html/score_list.php on line 67