ユーザーがこれの 1 つのレコードのみを保持し、いつでも自分の情報を更新できるプロファイル フォームがあります。まず、mysql update を使用して空のテーブルを更新できますか? 2 つの機能を実行するように送信をセットアップしようとしています。レコードが存在するかどうかに応じて、挿入または更新します。
if(isset($_POST['update']) && $profile['user_id'] == ""){
DB::getInstance()->insert_profile(
$_POST['user_id'],
$_POST['fname'],
$_POST['mname'],
$_POST['lname'],
$_POST['profilepic'],
$_POST['location'],
$_POST['tag'],
$_POST['email'],
$_POST['confemail'],
$_POST['newsletter'],
$_POST['height'],
$_POST['build'],
$_POST['eyecolour'],
$_POST['haircolour'],
$_POST['race'],
$_POST['nationality'],
$_POST['languages'],
$_POST['playingage'],
$_POST['accents'],
$_POST['aname'],
$_POST['aagency'],
$_POST['atelephone'],
$_POST['aemail'],
$_POST['aweb'],
$_POST['facebook'],
$_POST['twitter'],
$_POST['spotlight'],
$_POST['castingcall']);
}
else if (isset($_POST['update']) && $profile['user_id'] != ""){
hcDB::getInstance()->update_profile(
$_POST['user_id'],
$_POST['fname'],
$_POST['mname'],
$_POST['lname'],
$_POST['profilepic'],
$_POST['location'],
$_POST['tag'],
$_POST['email'],
$_POST['confemail'],
$_POST['newsletter'],
$_POST['height'],
$_POST['build'],
$_POST['eyecolour'],
$_POST['haircolour'],
$_POST['race'],
$_POST['nationality'],
$_POST['languages'],
$_POST['playingage'],
$_POST['accents'],
$_POST['aname'],
$_POST['aagency'],
$_POST['atelephone'],
$_POST['aemail'],
$_POST['aweb'],
$_POST['facebook'],
$_POST['twitter'],
$_POST['spotlight'],
$_POST['castingcall']);
}
これは機能せず、エラーも発生しません。どんなアイデアでも大歓迎です。
申し訳ありませんが、私の挿入および更新機能は次のとおりです。
public function update_profile (
$userID,$fname, $mname, $lname, $profilepic, $location, $tag, $email, $confemail, $newsletter,
$height, $build, $eyecolour, $haircolour, $race, $nationality, $languages,
$playingage, $accents, $aname, $aagency, $atelephone, $aemail, $aweb,
$facebook, $twitter, $spotlight, $castingcall){
$fname = $this->real_escape_string($fname);
$mname = $this->real_escape_string($mname);
$lname = $this->real_escape_string($lname);
$profilepic = $this->real_escape_string($profilepic);
$location = $this->real_escape_string($location);
$tag = $this->real_escape_string($tag);
$email = $this->real_escape_string($email);
$confemail = $this->real_escape_string($confemail);
$newsletter = $this->real_escape_string($newsletter);
$height = $this->real_escape_string($height);
$build = $this->real_escape_string($build);
$eyecolour = $this->real_escape_string($eyecolour);
$haircolour = $this->real_escape_string($haircolour);
$race = $this->real_escape_string($race);
$nationality = $this->real_escape_string($nationality);
$languages = $this->real_escape_string($languages);
$playingage = $this->real_escape_string($playingage);
$accents = $this->real_escape_string($accents);
$aname = $this->real_escape_string($aname);
$aagency = $this->real_escape_string($aagency);
$atelephone = $this->real_escape_string($atelephone);
$aemail = $this->real_escape_string($aemail);
$aweb = $this->real_escape_string($aweb);
$facebook = $this->real_escape_string($facebook);
$twitter = $this->real_escape_string($twitter);
$spotlight = $this->real_escape_string($spotlight);
$castingcall = $this->real_escape_string($castingcall);
$this->query("UPDATE profile SET
fname = '" . $fname . "', mname = '" . $mname . "',
lname = '" . $lname . "', profilepic = '" . $profilepic . "',
location = '" . $location . "', tag = '" . $tag . "',
email = '" . $email . "', confemail = '" . $confemail . "', newsletter = '" . $newsletter . "',
height = '" . $height . "', build = '" . $build . "',
eyecolour = '" . $eyecolour . "', haircolour = '" . $haircolour . "',
race = '" . $race . "', nationality = '" . $nationality . "',
languages = '" . $languages . "', playingage = '" . $playingage . "',
accents = '" . $accents . "', aname = '" . $aname . "',
aagency = '" . $aagency . "', atelephone = '" . $atelephone . "',
aemail = '" . $aemail . "', aweb = '" . $aweb . "',
facebook = '" . $facebook . "', twitter = '" . $twitter . "',
spotlight = '" . $spotlight . "', castingcall = '" . $castingcall. "', WHERE user_id = " . $userID or die(mysql_error()));
}
public function insert_profile(
$fname, $mname, $lname, $profilepic, $location, $tag, $email, $confemail, $newsletter,
$height, $build, $eyecolour, $haircolour, $race, $nationality, $languages,
$playingage, $accents, $aname, $aagency, $atelephone, $aemail, $aweb,
$facebook, $twitter, $spotlight, $castingcall){
$fname = $this->real_escape_string($fname);
$mname = $this->real_escape_string($mname);
$lname = $this->real_escape_string($lname);
$profilepic = $this->real_escape_string($profilepic);
$location = $this->real_escape_string($location);
$tag = $this->real_escape_string($tag);
$email = $this->real_escape_string($email);
$confemail = $this->real_escape_string($confemail);
$newsletter = $this->real_escape_string($newsletter);
$height = $this->real_escape_string($height);
$build = $this->real_escape_string($build);
$eyecolour = $this->real_escape_string($eyecolour);
$haircolour = $this->real_escape_string($haircolour);
$race = $this->real_escape_string($race);
$nationality = $this->real_escape_string($nationality);
$languages = $this->real_escape_string($languages);
$playingage = $this->real_escape_string($playingage);
$accents = $this->real_escape_string($accents);
$aname = $this->real_escape_string($aname);
$aagency = $this->real_escape_string($aagency);
$atelephone = $this->real_escape_string($atelephone);
$aemail = $this->real_escape_string($aemail);
$aweb = $this->real_escape_string($aweb);
$facebook = $this->real_escape_string($facebook);
$twitter = $this->real_escape_string($twitter);
$spotlight = $this->real_escape_string($spotlight);
$castingcall = $this->real_escape_string($castingcall);
$this->query("INSERT INTO profile(
`fname`, `mname`, `lname`, `profilepic`, `location`,
`tag`, `email`, `confemail`, `newsletter`, `height`, `build`,
`eyecolour`, `haircolour`, `race`, `nationality`,
`languages`, `playingage`, `accents`, `aname`,
`aagency`, `atelephone`, `aemail`, `aweb`,
`facebook`, `twitter`, `spotlight`, `castingcall`
)" . " VALUES
'" . $fname . "',
'" . $mname . "',
'" . $lname . "',
'" . $profilepic . "',
'" . $location . "',
'" . $tag . "',
'" . $email . "',
'" . $confemail . "',
'" . $newsletter . "',
'" . $height . "',
'" . $build . "',
'" . $eyecolour . "',
'" . $haircolour . "',
'" . $race . "',
'" . $nationality . "',
'" . $languages . "',
'" . $playingage . "',
'" . $accents . "',
'" . $aname . "',
'" . $aagency . "',
'" . $atelephone . "',
'" . $aemail . "',
'" . $aweb . "',
'" . $facebook . "',
'" . $twitter . "',
'" . $spotlight . "',
'" . $castingcall. "')");
}
そして私の形…
<form id="profile" action="{$HTTP_HOST}admin/profile.php" method="post" autocomplete="off">
そしてボタン:
<button class="submit" type="submit" value="update" name="update">Update</button>
ありがとう。