我有一个个人资料表格,用户只保留一份记录,并且可以随时更新他们的信息。首先,我可以使用 mysql update 来更新一个空表吗?我正在尝试设置提交以执行两个功能。插入或更新,取决于记录是否存在:
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>
谢谢。