동적으로 mysqli 테이블을 업데이트하면 조건이 저에게 효과적이지 않습니다. 도와주세요.동적으로 mysqli 테이블을 업데이트하는 방법 oopp의 조건
public function updateProfile($profile_picture, $username,$businessname, $town) {
$stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where profile_id= ? ");
$stmt->bind_param("ssssi",$profile_picture, $username,$businessname, $town, $profile_id);
$stmt->execute();
$stmt->close();
}
그러나 정적으로 내가이 작업을 수행 할 때 내가 모르는 작동하는 이유 :
public function updateProfile($profile_picture, $username, $businessname, $town) {
$stmt = $this->conn->prepare("UPDATE profile_information set profile_picture = ?, username= ?, businessname= ?, town= ? where profile_id= 4 ");
$stmt->bind_param("ssss",$profile_picture, $username,$businessname, $town);
$stmt->execute();
$stmt->close();
}
어떻게 updateProfile 함수를 호출 :
<?php
include './DbHandler.php';
$db = new DbHandler();
$response = array();
if ( isset($_POST['profile_picture']) && isset($_POST['username']) && isset($_POST['businessname']) && isset($_POST['town']) != '') {
$profile_picture = $_POST['profile_picture'];
$username = $_POST['username'];
$businessname = $_POST['businessname'];
$town = $_POST['town'];
$response = $db->updateProfile($profile_picture, $username, $businessname, $town);
} ?>
updateMyProfile.php에서 내 html 양식
<!doctype html>
<html lang="en">
<body>
<form name="uploadForm" method="post" action="updateMyprofile.php" >
<label>profilep</label> <input type="text"name="profile_picture" ><br><br>
<label>Uname</label> <input type="text" name="username" ><br><br>
<label>BName</label><input type="text" name="businessname"><br><br>
<label>Town </label> <input type="text" name="town" ><br><br>
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
내가 그 오류를 피하기 위해 할 일은 그 기능을 다음과 같습니다 또한 오류가 사라진 경우에도 작동하지 않습니다. '$ response = array(); if (isset ($ _ POST [ 'profile_picture']) && isset ($ _ POST [ 'username']) && isset ($ _ POST [ 'businessname']) && isset ($ _ POST [ 'town']) && isset ($ _POST [ 'profile_id'])! = '') { $ profile_picture = $ _POST [ 'profile_picture']; $ username = $ _POST [ 'username']; $ businessname = $ _POST [ 'businessname']; $ town = $ _POST [ 'town']; $ response = $ db-> createProfile ($ profile_picture, $ username, $ businessname, $ town, $ profile_id); }' – user3518835
@scaisEdge가 게시 한 답변은 'profile_id'를 매개 변수로 함수에 전달하지 않았거나 함수 내의 전역 변수로 사용할 수 없게되었습니다. '4'의 값을 하드 코딩하면 변수가 필요한 이유가 무효화됩니다. 만약 당신이'profile_id'를 POST하면, 매개 변수로 전달하거나 함수 내에서 POST 배열로부터 변수를 생성해야합니다. – RamRaider
함수 내에서 POST 배열로부터 어떻게 변수를 생성 할 수 있는지 모르겠습니다. 도움이 필요해. 지금 위의 코드는 위의 오류가 있지만 내 테이블에 업데이 트가 언제든지 해당 함수를 호출 – user3518835