简体   繁体   中英

Why won't my code update or insert into Oracle DB when nested in if's?

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); 
        }

    ?>

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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