SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    What is wrong with this code?

    I've got the following code, it's a submission form but it will not submit to the database and the if then statements don't work either. What is wrong?


    PHP Code:
    <?php 
    error_reporting
    (E_ALL); 
    ?>

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

    ?> 

    <html> 

    <head> 

    <title>The Sample Form</title> 

    </head> 

    <body> 

    <?php 

    if (!isset($_POST['submit'])) {  

    ?> 

    <form action="" method="post"> 

    Name: <input type="text" name="name"><br> 

    Favorite Color: <input type="text" name="color"><br> 

    <?php 

     

    if(isset($_POST['submit'])) { 

      
    mysql_connect($db_host$db_user$db_pwd); 

    mysql_select_db($db_name); 

    $sql mysql_query(

            update 

                authorize 

            set 

                lockedstatus = 'LOCKED' 

            where 

                username = 'testworker' 

        "
    ); 

          

     

          

    } else { 

        
    $sql mysql_query(

            select * from 

                authorize      

            where 

                username = 'testworker' 

            "
    ); 

              

        
    $rows mysql_fetch_assoc($sql); 

              

        if(
    $rows['lockedstatus'] == 'LOCKED') { 

            echo 
    '<input type="submit" value="Edit" disabled="disabled" />'

        } else { 

            echo 
    '<input type="submit" value="submit" name="submit" />'

        } 

              



     

     

    ?> 

     

    </form> 

    <?php 

    } else {

     
    mysql_connect($db_host$db_user$db_pwd); 

    mysql_select_db($db_name); 

    $color $_POST['color']; 

    mysql_query("UPDATE colors (name, color) VALUES ('testworker', '$color')"); 

    echo 
    "Success! Your color has been added!"



    ?> 

    </body> 

    </html>

  2. #2
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    because, you are calling the if-then thing inside a first condition.

    You are first asking,
    if the form is not submitted, show the form,
    if submitted, do query

    Inside the first condition, you are again calling a condition like, if submitted, etc.

    This will never be executed, as the logic suggests.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, so how do I fix it?


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
  •