简体   繁体   English

在特定列中插入值

[英]Inserting value in a certain column

I have a php program and i want to insert values into certain column. 我有一个php程序,我想在某些列中插入值。 here is my table. 这是我的桌子。

form_no | fullname | january | february | march | april | may | june | july
11111     smith, john

what is the right query code in doing this? 这样做正确的查询代码是什么? and the right way in checking if the cell already contains a value? 以及检查单元格是否已包含值的正确方法? raw table: https://drive.google.com/file/d/0B99TeByt30n2eHdLM0FER210cWM/edit?usp=sharing 原始表格: https//drive.google.com/file/d/0B99TeByt30n2eHdLM0FER210cWM/edit?usp = sharing

and here is my code in which i also tried to check if that cell has already a value. 这是我的代码,其中我还尝试检查该单元格是否已经有值。

$value_result = mysql_query("SELECT january FROM table_2014 WHERE form_no = '$formnumber'");
$value_rownum = mysql_num_rows($value_result);
if (!$value_result) {
    die(mysql_error());
}
if ( $value_rownum > 0 ) {
    echo "Already contributed!";
} else {
    $sql = "UPDATE `table_2014` SET january = '$contri_amnt' WHERE form_no = '$formnumber'";

    if (!mysql_query($sql,$con)) {
         die('Error: ' . mysql_error());
    }
}

Even if January is NULL you will still get a row, so counting the rows will give you 1, and you will never update it. 即使一月为NULL,您仍然会得到一行,因此对行进行计数将为您提供1,并且您将永远不会对其进行更新。

You need to use mysql_fetch_assoc or mysql_fetch_object to check if the result actually has a value. 您需要使用mysql_fetch_assoc或mysql_fetch_object来检查结果是否真正具有值。 OR, change your query to 或者,将查询更改为

SELECT january FROM table_2014 WHERE form_no = '$formnumber' AND january IS NOT NULL 从table_2014中选择一月form_no ='$ formnumber'并且一月不为空

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM