SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Addict
    Join Date
    Apr 2002
    Location
    Miami
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this code execute no matter what

    When I set the variable form a html select list it works properly.
    When I dont set the variable it still executes, can you tell me why
    Thanks!

    PHP Code:
    <?php    
        
    if(isset($_POST['sentto']) && ($_POST['sentto'] != '')) {
        
    $jobsql "UPDATE job SET
        sentto = '
    $sentto'
        WHERE jobid = '
    $job' ";

        if(!@
    mysql_query($jobsql)) {
        echo(
    "error adding to job table" mysql_error() . "sorry");
        }
        }
    ?>
    I just want to add that if I set the select option value in the form to have a not selected value of "0" and modify the != to be !='0' then it works and will not update that field

  2. #2
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    When you say that you don't set the variable are you still submitting the form?
    Wayne Luke
    ------------


  3. #3
    SitePoint Addict
    Join Date
    Apr 2002
    Location
    Miami
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes I am still submiting the form. The option value of the drop down list would be empty. This then has the effect of clearing the field in the database of its prior value. I just edited my post. When I use !='0' and set the unselected value of drop down menu to 0 it works???? I dont get it

  4. #4
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Most likely because it isn't being interpreted as a string. Loose data typing can do weird things like that.
    Wayne Luke
    ------------


  5. #5
    SitePoint Addict
    Join Date
    Apr 2002
    Location
    Miami
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the html that sets the variable

    <select name="sentto">
    <option value="0">Department</option>
    <option value="1">Data Processing</option>
    <option value="2">Fullfillment</option>
    <option value="3">Bar Code</option>
    <option value="4">Metering</option>
    <option value="5">Hand Sort</option>
    <option value="6">USPS</option>
    </select>

    For this purpose the 0 value works okay
    but is there a correct way to do this or
    is this the correct way.

  6. #6
    Your Lord and Master, Foamy gold trophy Hierophant's Avatar
    Join Date
    Aug 1999
    Location
    Lancaster, Ca. USA
    Posts
    12,305
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    This is a correct way... Comparing against 0 is no more resource hungry than comparing against NULL or an empty string.
    Wayne Luke
    ------------


  7. #7
    SitePoint Addict
    Join Date
    Apr 2002
    Location
    Miami
    Posts
    214
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, thanks for that


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •