SitePoint Sponsor

User Tag List

Page 2 of 2 FirstFirst 12
Results 26 to 45 of 45
  1. #26
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I still need some help with this, if anybody can help.

  2. #27
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please paste the code you have currently. We can work from that.

  3. #28
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <?php 
    $db_host 
    "localhost"
    $db_user "lefteh"
    $db_pwd "1234"
    $db_name "MyDB"
    mysql_connect($db_host$db_user$db_pwd); 
    mysql_select_db($db_name); 
    ?> 
    <html> 
    <head> 
    <title>My first MySQL form submission</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'])) { 
          
    $sql mysql_query(
            update 
                authorize 
            set 
                LockStatus = 'LOCKED' 
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
        "
    ); 
          

          
    } else { 
        
    $sql mysql_query(
            select * from 
                authorize      
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
            "
    ); 
              
        
    $rows mysql_fetch_assoc($sql); 
              
        if(
    $rows['LockStatus'] == 'LOCKED') { 
            echo 
    '<input type="submit" value="Edit" disabled="disabled" />'
        } else { 
            echo 
    '<input type="submit" value="submit" name="submit" />'
        } 
              



    ?> 

    </form> 
    <?php 
    } else { 
    $name $_POST['name']; 
    $color $_POST['color']; 
    mysql_query("INSERT INTO `colors` (name, favoriteColor) VALUES ('$name', '$color')"); 
    echo 
    "Success! Your favourite colour has been added!"

    ?> 
    </body> 
    </html>

  4. #29
    SitePoint Enthusiast Chousho's Avatar
    Join Date
    Jun 2006
    Posts
    97
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Umm, the thing that keeps coming up is that you don't have anything in the form action. Look back a few posts to see what's been mentioned several times to include there.

    Also, mysql_fetch_assoc() names the variables based on the fields in the table. So $rows['LockStatus'] would mean you have a field named "LockStatus" in your authorize table?

    Could you look at your tables again and copy word for word the table names, and all of the fields in them?

    This will take a little bit of effort, because we can't code for you if the table information isn't given or correct.

  5. #30
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The table names are all correct, this is just a sample form of how I laid it out none of the table names are as they appear in the database for the example. You do not have to have something in the form action in order to submit items into the database.

  6. #31
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    run the following.....
    PHP Code:
    <?php 
    $db_host 
    "localhost"
    $db_user "lefteh"
    $db_pwd "1234"
    $db_name "MyDB"
    mysql_connect($db_host$db_user$db_pwd); 
    mysql_select_db($db_name); 
    ?> 
    <html> 
    <head> 
    <title>My first MySQL form submission</title> 
    </head> 
    <body> 

    <form action="" method="post"> 
    Name: <input type="text" name="name"><br> 
    Favorite Color: <input type="text" name="color"><br> 
    <?php 

    if(isset($_POST['submit'])) { 
           
    $sql mysql_query(
            update 
                authorize 
            set 
                LockStatus = 'LOCKED' 
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
        "
    ); 
        
        
    $name $_POST['name']; 
    $color $_POST['color']; 
           
    $sql_2 mysql_query("
            INSERT INTO 
                `colors` 
            (name, favoriteColor) 
            VALUES 
            ('
    $name', '$color')
            "
    ); 
    echo 
    "Success! Your favourite colour has been added!";         
           
    } else { 
        
    $sql mysql_query(
            select * from 
                authorize       
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
            "
    ); 
               
        
    $rows mysql_fetch_assoc($sql); 
               
        if(
    $rows['LockStatus'] == 'LOCKED') { 
            echo 
    '<input type="submit" value="Edit" disabled="disabled" />'
        } else { 
            echo 
    '<input type="submit" value="submit" name="submit" />'
        } 
               



    ?> 

    </form> 
    </body> 
    </html>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  7. #32
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well it didn't bomb out, but it didn't submit to the database either.

  8. #33
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I think the if submit has to be above the form

  9. #34
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    Generally you can have it where you like, try the following
    PHP Code:
    <?php 
    $db_host 
    "localhost"
    $db_user "lefteh"
    $db_pwd "1234"
    $db_name "MyDB"
    mysql_connect($db_host$db_user$db_pwd); 
    mysql_select_db($db_name); 

    if(isset(
    $_POST['submit'])) { 
            
    $sql mysql_query(
            update 
                authorize 
            set 
                LockStatus = 'LOCKED' 
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
        "
    ); 
         
         
    $name $_POST['name']; 
    $color $_POST['color']; 
            
    $sql_2 mysql_query(
            INSERT INTO 
                `colors` 
            (name, favoriteColor) 
            VALUES 
            ('
    $name', '$color') 
            "
    ); 
    echo 
    "Success! Your favourite colour has been added!";          
            


    ?> 
    <html> 
    <head> 
    <title>My first MySQL form submission</title> 
    </head> 
    <body> 

    <form action="" method="post"> 
    Name: <input type="text" name="name"><br> 
    Favorite Color: <input type="text" name="color"><br> 
    <?php 
        $sql 
    mysql_query(
            select * from 
                authorize        
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
            "
    ); 
                
        
    $rows mysql_fetch_assoc($sql); 
                
        if(
    $rows['LockStatus'] == 'LOCKED') { 
            echo 
    '<input type="submit" value="Edit" disabled="disabled" />'
        } else { 
            echo 
    '<input type="submit" value="submit" name="submit" />'
        } 
                



    ?> 

    </form> 
    </body> 
    </html>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  10. #35
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    showed a blank page.

  11. #36
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not really sure what's making it bomb, it looks okay to me.

  12. #37
    SitePoint Member
    Join Date
    Jun 2007
    Location
    England
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Im seeing it loud and clear :P
    Feel the full force of free online games at www.buddygaming.com

  13. #38
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oh really?

  14. #39
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    assuming you have session_start(); at the top of the script.....

    Does is fail on load or on submit?
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  15. #40
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On submit

  16. #41
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Basically what it does is just take you back to the original form, without submitting any of the data.

  17. #42
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,807
    Mentioned
    158 Post(s)
    Tagged
    3 Thread(s)
    This is turning into a mammoth thread!
    New code
    PHP Code:
    <?php 
    session_start
    ();

    $db_host "localhost"
    $db_user "lefteh"
    $db_pwd "1234"
    $db_name "MyDB"
    mysql_connect($db_host$db_user$db_pwd); 
    mysql_select_db($db_name); 

    if(isset(
    $_POST['submit'])) { 
             
    $sql mysql_query(
            update 
                authorize 
            set 
                LockStatus = 'LOCKED' 
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
        "
    ) or die(mysql_error()); 
          
          
    $name $_POST['name']; 
    $color $_POST['color']; 
             
    $sql_2 mysql_query(
            INSERT INTO 
                `colors` 
            (name, favoriteColor) 
            VALUES 
            ('
    $name', '$color') 
            "
    ) or die(mysql_error()); 
    echo 
    "Success! Your favourite colour has been added!";           
             


    ?> 
    <html> 
    <head> 
    <title>My first MySQL form submission</title> 
    </head> 
    <body> 

    <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> 
    Name: <input type="text" name="name"><br> 
    Favorite Color: <input type="text" name="color"><br> 
    <?php 
        $sql 
    mysql_query(
            select * from 
                authorize         
            where 
                user_name = '"
    $_SESSION['user_name'] ."' 
            "
    ); 
                 
        
    $rows mysql_fetch_assoc($sql); 
                 
        if(
    $rows['LockStatus'] == 'LOCKED') { 
            echo 
    '<input type="submit" value="Edit" disabled="disabled" />'
        } else { 
            echo 
    '<input type="submit" value="submit" name="submit" />'
        } 
                 



    ?> 

    </form> 
    </body> 
    </html>
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  18. #43
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The form and everything shows up, and when I press submit it takes me to a blank page. I look in my database and none of the variables have been updated.

  19. #44
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Is there another way to go about this?

  20. #45
    SitePoint Guru
    Join Date
    Apr 2007
    Posts
    690
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm still seeking solutions.


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
  •