duanbage2161 2014-07-09 14:19
浏览 74
已采纳

当嵌套在if中时,为什么我的代码不会更新或插入到Oracle DB中?

I am attempting to create code that takes user input via HTML form, and processes it using if statements (see below).

When I input data and click submit, no errors are reported. However, no data is updated in the oracle DB either. Next I will walk you through my logic, lines will be marked by /* ## */ to make it easier to understand.

So, the user inputs the week they are editing [/ 01 /]. Next is the day of the week they are editing (below / 01 /). These are the two values being used in the "if" statement (see handler) where my problem is.

Line designated / 02 / in handler is checking to see if there are any existing weeks matching that inputted by the user to edit.

Line designated / 03 / in handler beigns the if statement that takes $week, the row which may exist, and either edits or inserts depending on whether or not it is set.

There are 8 columns in this database: WEEK, and all days of the week (MONDAY, TUESDAY...SUNDAY).

Any help is greatly appreciated, TIA!

Form:

    <div align="center">
        <span style="font-size:60px;">
            Day to Day Tree Events - Update Page <br/>
            Be very cautious when editing this page. <br>
            Misformatting can cause data to be deleted or altered incorrectly. <br>
        </span>
    </div>

    <div align="center">
        <form method="post" action="UpdateInfo_Tree.php">
            <span style="font-size:30px;">
                <u>As Of:[mm/dd/yyyy]:<input type="date" name="TREE_updated" value="<?php echo $row['TREE_DATE']; ?>"><br>
/ 01 /          Week [mm/dd/yyyy]:<input type="number" name="TREE_week" value="<?php echo $row['TREE_WEEK']; ?>"><br> /* 01 */
                Day of the Week: <select name="TREE_day">
                    <option value="MONDAY">Monday</option><br>
                    <option value="TUESDAY">Tuesday</option><br>
                    <option value="WEDNESDAY">Wednesday</option><br>
                    <option value="THURSDAY">Thursday</option><br>
                    <option value="FRIDAY">Friday</option><br>
                    <option value="SATURDAY">Saturday</option><br>
                    <option value="SUNDAY">Sunday</option><br>
                </select><br>
                Number Of Tree Events:<input type="number" name="TREE_events" value=" "><br></u>
                <input type="submit" value="Submit">

            </span>
        </form>
    </div>

Handler:

    <?
        $TREE_UPDATED = $_POST['TREE_updated'];
        $TREE_WEEK = $_POST['TREE_week'];
        $TREE_DAY = $_POST['TREE_day'];
        $TREE_EVENTS = $_POST['TREE_events'];

 / 02 /     $objConnect = oci_connect("user", "pass", "(description=(address=(protocol=tcp)(host=host)(port=1533))(connect_data=(service_name=sid)))");
        $weekSQL =  "SELECT * FROM INTOXDM.LSS_TREE WHERE WEEK = '$TREE_WEEK'";
        $weekParse = oci_parse($objConnect, $weekSQL);  
        $weekExecute = oci_execute($weekParse);
 \ 02 \     $week = oci_fetch_all($weekParse,$week1);

        if($week = 1)) {
            $updateSQL =  "UPDATE INTOXDM.LSS_TREE SET 
                    $TREE_DAY = '$TREE_EVENTS' 
                    WHERE WEEK = '$TREE_WEEK'";

            $updateParse = oci_parse($objConnect, $updateSQL);  
            $updateExecute = oci_execute($updateParse); 
        } else {
            $insertSQL = "insert into INTOXDM.LSS_TREE (WEEK, '$TREE_DAY') values ('$TREE_WEEK', '$TREE_EVENTS')";
            $insertParse = oci_parse($objConnect, $insertSQL);  
            $insertExecute = oci_execute($insertParse); 
        }

    ?>
  • 写回答

1条回答 默认 最新

  • doulu4534 2014-07-09 14:33
    关注

    The following will always evaluate as true, you've missed out an equals sign.

    if($week = 1)) {
    

    ie, should be:

    if($week == 1)) {
    

    A single equals sign is an assignment, you are setting the variable week to 1. This will always evaluate to true. A double equals sign is a comparison, you are comparing week to 1.

    http://php.net/manual/en/language.operators.assignment.php

    http://www.php.net/manual/en/language.operators.comparison.php

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 C++实现删除N个数据列表共有的元素
  • ¥15 Visual Studio问题
  • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
  • ¥20 求一个html代码,有偿
  • ¥100 关于使用MATLAB中copularnd函数的问题
  • ¥20 在虚拟机的pycharm上
  • ¥15 jupyterthemes 设置完毕后没有效果
  • ¥15 matlab图像高斯低通滤波
  • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗
  • ¥15 钢筋实图交点识别,机器视觉代码