SitePoint Sponsor

User Tag List

Page 1 of 2 12 LastLast
Results 1 to 25 of 29

Hybrid View

  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is wrong with this if then statement?

    PHP Code:
    <?php
    $db_host 
    "1234";
    $db_user "1234";
    $db_pwd "1234";
    $db_name "1234";
    mysql_connect($db_host$db_user$db_pwd); 
    mysql_select_db($db_name); 
    ?>

    <?php 

    if ( $_POST['lock'] == 'LOCKED' ) {
    mysql_query("update authorize set lockedstatus='LOCKED'"); 

    } elseif ( 
    $_POST['lock'] == 'UNLOCKED'] {
    mysql_query("update authorize set lockedstatus='UNLOCKED'"); 

    echo 
    "You have sucessfully switched it to $_POST['lock'] status";
    ?>

  2. #2
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no ) on the elseif, instead you used a ]

  3. #3
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I also don't see a closing '}'.

  4. #4
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its still not working.

  5. #5
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yep, so to sum up:

    PHP Code:
    if ( $_POST['lock'] == 'LOCKED' ) {

    mysql_query("update authorize set lockedstatus='LOCKED'"); 

    } elseif ( 
    $_POST['lock'] == 'UNLOCKED'] ) {

    mysql_query("update authorize set lockedstatus='UNLOCKED'"); 

    }

    echo 
    "You have sucessfully switched it to $_POST['lock'] status"
    Ryan Price
    Subscribe to my blog for regular tips and tricks

  6. #6
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's still blowing up somewhere guys.

  7. #7
    SitePoint Addict darkwater23's Avatar
    Join Date
    Nov 2005
    Location
    Omaha, NE
    Posts
    335
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do you have an error message? You're not checking to see if $_POST['lock'] is set before you do a compare. That can cause an error, too.

  8. #8
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (isset($_POST['lock'])) {
      
    $var $_POST['lock'];

      if (  
    $var == 'LOCKED') {
        
    mysql_query("update authorize set lockedstatus='LOCKED'"); 
      } elseif ( 
    $var == 'UNLOCKED') {
        
    mysql_query("update authorize set lockedstatus='UNLOCKED'"); 
      }
      echo 
    "You have sucessfully switched it to $_POST['lock'] status"


  9. #9
    SitePoint Addict
    Join Date
    May 2005
    Location
    London, ON
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Andrewaclt View Post
    PHP Code:
    if (isset($_POST['lock'])) {
      
    $var $_POST['lock'];

      if (  
    $var == 'LOCKED') {
        
    mysql_query("update authorize set lockedstatus='LOCKED'"); 
      } elseif ( 
    $var == 'UNLOCKED') {
        
    mysql_query("update authorize set lockedstatus='UNLOCKED'"); 
      }
      echo 
    "You have sucessfully switched it to $_POST['lock'] status"

    Try adding this too:
    PHP Code:
    if (isset($_POST['lock'])) {
      
    $var $_POST['lock'];

      if (  
    $var == 'LOCKED') {
        
    mysql_query("update authorize set lockedstatus='LOCKED'") or die("Query Failed: ".mysql_error()); 
      } elseif ( 
    $var == 'UNLOCKED') {
        
    mysql_query("update authorize set lockedstatus='UNLOCKED'") or die("Query Failed: ".mysql_error()); 
      }
      echo 
    "You have sucessfully switched it to $_POST['lock'] status"

    Ryan Price
    Subscribe to my blog for regular tips and tricks

  10. #10
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well I echoed the post variable and it showed the correct data. What do you mean if the variable is set?

  11. #11
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    see above, fixed code.

  12. #12
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Andrew, that bombed out.

  13. #13
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    jeanco that bombed too

  14. #14
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No error messages displayed

  15. #15
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    if (isset($_POST['lock'])) {
      
    $var $_POST['lock'];
      echo 
    $var;
      if (  
    $var == 'LOCKED') {
        
    mysql_query("update authorize set lockedstatus='LOCKED'") or die("Query Failed: ".mysql_error());
      } elseif ( 
    $var == 'UNLOCKED') {
        
    mysql_query("update authorize set lockedstatus='UNLOCKED'") or die("Query Failed: ".mysql_error());
      }
      echo 
    "You have sucessfully switched it to $_POST['lock'] status"
    } else {
      echo 
    "Lock not set";


  16. #16
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    blank page.

  17. #17
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you get a blank page then something really bad is wrong look in your file system and see if it's logging errors to a file somewhere. like in htdocs or whatever your folder is when you first log in.

  18. #18
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have a file system I don't think. Do I need something else in the if thens statement to contact it with the database information?

  19. #19
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Here is the page leading up to the if then statement:

    PHP Code:
    <form action="locked.php" method="post">
    Would you like to lock or unlock?<select size="1" name="lock">
                <
    option value="UNLOCKED">Unlock</option>
                <
    option value="LOCKED">Lock</option>

                </
    select><br>
    <
    input type="submit" name="submit" value="submit" />
    </
    form

  20. #20
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    put error_reporting(E_ALL); in the beginning of your file and see what error you have on the browser or the error log.

  21. #21
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No errors were displayed.

  22. #22
    SitePoint Evangelist Andrewaclt's Avatar
    Join Date
    Dec 2003
    Location
    Raleigh, NC
    Posts
    535
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Look at to where you upload the php files, look for an error log, on my shared host when I first login I login to a folder containing public_html, etc in this folder php errors are logged. See if there is something similar.

  23. #23
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't have anything like that unfortunately. Can someone try to replicate this and see if it works for you?

  24. #24
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    96
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you have error_reporting turned on? eg: display_errors On
    you can check by making simple page test.php with this code:
    <?php phpinfo(); ?>

  25. #25
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    685
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's not turned on.


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
  •