update table 에 관한 문의 드립니다.
본문
안녕하세요.
업데이트 테이블을 만들었는데 DB가 업데이트가 안됩니다.
어떻게 하면 될까요?
고수님들의 조언 부탁드립니다.
감사합니다.
Error 내용은
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /www/update.php on line 47
Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in /www/update.php on line 53
Warning: mysqli_query() expects parameter 1 to be mysqli, null given in /www/update.php on line 47
핑포미션 실적 리포트 업데이트 REPOT로그아웃
Record Modified Successfully
입니다.
Line 47 은
WHERE input_date='" . $_POST['input_date'] . "'");
Line 53 은
$row= mysqli_fetch_array($result);
입니다.
updatedb.php
<?php
$servername='localhost';
$username='dbuser';
$password='????';
$dbname = "dbserver";
$con=mysqli_connect($servername,$username,$password,"$dbname");
if(count($_POST)>0) {
mysqli_query($conn,"UPDATE updatetable SET
uesrname01='" . $_POST['name01'] . "', password01='" . $_POST['password01'] . "', age01='" . $_POST['age01'] . "' .
uesrname02='" . $_POST['name02'] . "', password02='" . $_POST['password02'] . "', age01='" . $_POST['age02'] . "' .
uesrname03='" . $_POST['name03'] . "', password03='" . $_POST['password03'] . "', age01='" . $_POST['age03'] . "'
WHERE input_date='" . $_POST['input_date'] . "'");
$message = "Record Modified Successfully";
}
$row= mysqli_fetch_array($result);
?>
update.php
<?php
include_once './updatedb.php';
?>
<!DOCTYPE html>
중간생략
<table id="newspaper-a">
<form method="post" action="">
<div><?php if(isset($message)) { echo $message; } ?>
</div>
<form>
<div style="width:400px; margin-bottom:10px; margin-right:10px; margin-top:68px; float: right; flex-basis: 15% display: inline-block; vertical-align: middle;
}">
<input type="text" name="input_date" value="input_date" class="datepicker inp" placeholder="가입 날짜" readonly="true" />
<button type="submit">업데이트 하기</button>
</div>
</form>
<script>
$.datepicker.setDefaults({
closeText: "닫기",
prevText: "이전달",
nextText: "다음달",
currentText: "오늘",
monthNames: ["1월", "2월", "3월", "4월", "5월", "6월",
"7월", "8월", "9월", "10월", "11월", "12월"
],
monthNamesShort: ["1월", "2월", "3월", "4월", "5월", "6월",
"7월", "8월", "9월", "10월", "11월", "12월"
],
dayNames: ["일요일", "월요일", "화요일", "수요일", "목요일", "금요일", "토요일"],
dayNamesShort: ["일", "월", "화", "수", "목", "금", "토"],
dayNamesMin: ["일", "월", "화", "수", "목", "금", "토"],
weekHeader: "주",
dateFormat: "yy-mm-dd", // 날짜형태 예)yy년 m월 d일
firstDay: 0,
isRTL: false,
showMonthAfterYear: true,
yearSuffix: "년"
})
$(".datepicker").datepicker({
//minDate: 0
})
</script>
<!-- } -->
<tr>
<th> <font face="Arial">NO</font> </th>
<th> <font face="Arial">선청장소</font> </th>
<th> <font face="Arial">신청방법</font> </th>
<th> <font face="Arial">이름</font> </th>
<th> <font face="Arial">비밀번호</font> </th>
<th> <font face="Arial">나이</font> </th>
</tr>
<tr><td>1</td><td>학교</td><td>설문지</td><td><input type="text" class="'name01" id="'name01" name="'name01" value="<?php echo $row[''name01']; ?>" placeholder=""></td><td><input type="text" class="password01" id="password01" name="password01" value="<?php echo $row['password01']; ?>" placeholder=""></td><td><input type="text" class="age01" id="age01" name="age01" value="<?php echo $row['age01']; ?>" placeholder=""></td><td>
<tr><td>2</td><td>인터넷</td><td>온라인</td><td><input type="text" class="name02" id="name02" name="name02" value="<?php echo $row['name02']; ?>" placeholder=""></td><td><input type="text" class="password02" id="password02" name="password02" value="<?php echo $row['password02']; ?>" placeholder=""></td><td><input type="text" class="age02" id="age02" name="age02" value="<?php echo $row['age02']; ?>" placeholder=""></td><td>
<tr><td>3</td><td>전화</td><td>상담</td><td><input type="text" class="name03" id="name03" name="name03" value="<?php echo $row['name03']; ?>" placeholder=""></td><td><input type="text" class="password03" id="password03" name="password03" value="<?php echo $row['password03']; ?>" placeholder=""></td><td><input type="text" class="age03" id="age03" name="age03" value="<?php echo $row['age03']; ?>" placeholder=""></td><td>
</form>
</table>
생략
!-->!-->
답변 3
<?php
$servername='localhost';
$username='dbuser';
$password='????';
$dbname = "dbserver";
$con=mysqli_connect($servername,$username,$password,$dbname);
if(count($_POST)>0) {
$sql = "
UPDATE updatetable SET
uesrname01='" . $_POST['name01'] . "', password01='" . $_POST['password01'] . "', age01='" . $_POST['age01'] . "' .
uesrname02='" . $_POST['name02'] . "', password02='" . $_POST['password02'] . "', age01='" . $_POST['age02'] . "' .
uesrname03='" . $_POST['name03'] . "', password03='" . $_POST['password03'] . "', age01='" . $_POST['age03'] . "'
WHERE input_date='" . $_POST['input_date'] . "'";
$result = mysqli_query($conn, $sql);
$message = "Record Modified Successfully";
if ($result)
echo $message;
}
//$row = mysqli_fetch_array($result);
?>
$result = mysqli_query($conn, $sql);
->
$result = mysqli_query($con, $sql);
line 49 번째에
변수는 $con 으로 해놓으셨으면서 왜 $conn 으로 넣으셨는지.....
$con=mysqli_connect($servername,$username,$password,$dbname);
$con 으로 넣으세요
답변을 작성하시기 전에 로그인 해주세요.