我所做的是:
我向用户提供了进度条,随着用户填充/清空表单中的字段( +/- 10% ),进度条将增加或减少,当用户提交表单时,该字段将被更新到数据库。此进度条通知用户用户完成了多少百分比配置文件。
我所面临的问题是:
我提供了多个update查询,每当它满足if语句时都会运行。所有的if语句和查询都在工作,因为我已经检查过了。但是,数据库中进度条字段的值只更新一次,或者在用户填充字段时增加,或者在用户清空字段时减少。如果用户在所有字段中更新--在这种情况下--它也在增加或减少10%
这是我的代码:
<?
include('includes/include.inc.php');
protect_seeker_page();
$loginLine=mysql_fetch_array(mysql_query
("select * from tb_user_login where user_login_id='$_SESSION[SEEKER_ID]'"));
$userLine=mysql_fetch_array(mysql_query
("select * from tb_user where user_login_id='$_SESSION[SEEKER_ID]'"));
$metadataLine=mysql_fetch_array(mysql_query
("select * from tb_user_metadata where user_login_id='$_SESSION[SEEKER_ID]'"));
$company=$userLine['user_progress']+10;
$company2=$userLine['user_progress']-10;
$skill=$userLine['user_progress']+10;
$skill2=$userLine['user_progress']-10;
$ind=$userLine['user_progress']+10;
$ind2=$userLine['user_progress']-10;
$resume=$userLine['user_progress']+10;
$resume2=$userLine['user_progress']-10;
if($_POST['Submit']=='Update'){
if($userLine['user_company_name']=="" and $_POST['user_company_name']!=""){
mysql_query
("update tb_user set user_progress='".$company."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($userLine['user_skills_id']=="" and $_POST['user_skills']!="")
{
mysql_query("update tb_user set user_progress='".$skill."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($userLine['user_resume_title']=="" and $_POST['user_resume_title']!=""){
mysql_query("update tb_user set user_progress='".$resume."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($userLine['user_industry_id']==0 and $_POST['industry_name']!=""){
echo mysql_query("update tb_user set user_progress='".$ind."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($_POST['user_company_name']=="" and $userLine['user_company_name']!=""){
mysql_query("update tb_user set user_progress='".$company2."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($_POST['user_skills']=="" and $userLine['user_skills_id']!=""){
mysql_query("update tb_user set user_progress='".$skill2."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($_POST['user_resume_title']=="" and $userLine['user_resume_title']!=""){
mysql_query("update tb_user set user_progress='".$resume2."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
if($_POST['industry_name']=="" and $userLine['user_industry_id']!=0){
mysql_query("update tb_user set user_progress='".$ind2."'
where user_login_id='$_SESSION[SEEKER_ID]'"); }
}
?>发布于 2013-12-19 09:58:46
使用以下代码:
$progress = $userLine['user_progress'];
if($_POST['Submit']=='Update'){
if($userLine['user_company_name']=="" and $_POST['user_company_name']!=""){
$progress +=10;
}
if($userLine['user_skills_id']=="" and $_POST['user_skills']!=""){
$progress +=10;
}
if($userLine['user_resume_title']=="" and $_POST['user_resume_title']!=""){
$progress +=10;
}
if($userLine['user_industry_id']==0 and $_POST['industry_name']!=""){
$progress +=10;
}
if($_POST['user_company_name']=="" and $userLine['user_company_name']!=""){
$progress -=10;
}
if($_POST['user_skills']=="" and $userLine['user_skills_id']!=""){
$progress -=10;
}
if($_POST['user_resume_title']=="" and $userLine['user_resume_title']!=""){
$progress -=10;
}
if($_POST['industry_name']=="" and $userLine['user_industry_id']!=0){
$progress -=10;
}
mysql_query("update tb_user set user_progress='".$progress."'
where user_login_id='$_SESSION[SEEKER_ID]'");
}在您的代码中,您总是在表中添加当前值为+/-10的+/- 10,所以它总是添加+/- 10、not +/- 20和/-30,等等。所以你需要像我建议的那样使用它。
注意:不要使用mysql_*,因为它已经被废弃了。 中转站总是使用mysqli_*或PDO。
https://stackoverflow.com/questions/20677975
复制相似问题