SitePoint Sponsor

User Tag List

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

    Database submission from only submitting one set of data?

    I have the following code, it needs to submit all mysql queries, but for some reason it's only submitting the top one, and completely bombing the second one.


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

    ?> 


    <?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' 

        "
    );  


    ?> 


    <html> 

    <head> 

    <title>The Sample Form</title> 

    </head> 

    <body> 




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

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

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

    <input type="submit" name="submit" value="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
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    That's because it is in if/else statement. That means only one will run based on the results of the if statement.

  3. #3
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay, well I need to make it so If they post that both will run?

  4. #4
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    Then remove the if/else statement.

  5. #5
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Can you show me an example?

  6. #6
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Do I just need to remove the else, and put the two statements togethER?

  7. #7
    He's No Good To Me Dead silver trophybronze trophy stymiee's Avatar
    Join Date
    Feb 2003
    Location
    Slave I
    Posts
    23,424
    Mentioned
    2 Post(s)
    Tagged
    1 Thread(s)
    That would do it

  8. #8
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I can't seem to get that to work?


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
  •