php-mysql没有以正确的方式更新行


php mysql not updating row in proper way

我有一列的名称为所有格1,在这列中我连接了$month$年,但问题是,当我只更新$month时,$year的值是圈,但当我只升级$year时,$month不圈,而是$year用旧值和新值更新列,比如,如果月份是五月,旧年份是2013,当我只用2014年更新年份时,它显示的输出是20132014年五月,这是我的代码

<select id="month" name="month" >
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
</select>
<select id="year" name="year">
<option value="2012">2012</option>
<option value="2013">2013</option>
<option value="2014">2014</option>
<option value="2015">2015</option>
<option value="2016">2016</option>
</select>
$month=@$_POST['month'];
$year=@$_POST['year'];
$arr = array($month, $year);
$possession1 = join("", $arr);
$updateSale="update sale set possession='$possession1' where id='$update_id'";
$r=mysql_query($updateSale);

试试这个,使用isset检查post值,

if(isset($_POST['month']) && isset($_POST['year'])){
 $month = $_POST['month'];
 $year = $_POST['year'];
 $possession1 = $month. " ".$year;
 $updateSale="update sale set possession='".$possession1."' where id='$update_id'";
 $r=mysql_query($updateSale);
}

将您的查询更正为以下内容--

$updateSale="update sale set possession='".$possession1."' where id='".$update_id."'";