Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder
    Join Date
    Jul 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    To allow user to change their selection after submission

    Hi

    Can anyone help me with the following:
    I want to allow user to be able to change their selection after submitting the form.

    Previously, I have written the code in this way:

    if (mysql_num_rows($result1) < 1)
    {
    $sql = "INSERT INTO student_activities (s_grade, s_tutorgroup, s_surname, s_forname, option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
    $result = mysql_query($sql);
    echo "Thank you! Your activities have been submitted.\n";
    }

    else if(mysql_num_rows($result1) > 0)
    {
    Echo "Sorry, you've submitted your activities options.";
    }

    mysql_close();
    ?>

    How do modify the codes?

    Thanks!

  • #2
    Super Moderator
    Join Date
    May 2002
    Location
    Perth Australia
    Posts
    4,051
    Thanks
    10
    Thanked 94 Times in 92 Posts
    does your table have a unique identifying field ? eg 'id'
    you just need to UPDATE the right record , guessing here that you have an autoincrement column somewhere in your table...

    PHP Code:
    <?
    $idfield
    '' //<<add the name of the autoincrement field here
    if( mysql_num_rows$result1 ) < ){
        
    $sql "INSERT INTO student_activities (s_grade, s_tutorgroup, s_surname, s_forname, option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
        
    $result mysql_query$sql );
    /* grab the autoincrement value */
        
    $insert_id mysql_insert_id() ;
        echo 
    "Thank you! Your activities have been submitted.\n";
    }else{ 
    // no need for the else //
        
    $sql "UPDATE student_activities SET s_grade='$grade' , s_tutorgroup='$tutorgroup', s_surname='$name2', s_forname='$name1' , option1='$option1' , option2='$option2' , option3='$option3' WHERE $idfield=$id ";
        
    $result mysql_query$sql ) ;
        echo 
    "Thank you! Your activities have been updated.\n" ;
    }
    mysql_close();
    ?>
    if you do not have an automincrement id column then you need to UPDATE //blah// WHERE $unique_field = 'unique_data'
    resistance is...

    MVC is the current buzz in web application architectures. It comes from event-driven desktop application design and doesn't fit into web application design very well. But luckily nobody really knows what MVC means, so we can call our presentation layer separation mechanism MVC and move on. (Rasmus Lerdorf)

  • #3
    New Coder
    Join Date
    Jul 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for your reply.

    There's no ID column.

    I tried putting the coding as below:
    if (mysql_num_rows($result1) < 1)
    {
    $sql = "INSERT INTO students_activities (s_grade,s_tutorgroup,s_surname,s_forename,option1,option2,option3) VALUES ('$grade','$tutorgroup','$name2','$name1','$option1','$option2','$option3')";
    $result = mysql_query($sql);
    echo "Thank you! Your activities have been submitted.\n";
    }
    else
    {
    $sql = "UPDATE student_activities SET s_grade='$grade',s_tutorgroup='$tutorgroup',s_surname='$name2',s_forename='$name1',option1='$option1 ',option2='$option2',option3='$option3' WHERE s_forename = '$name1' && s_surname = '$name2' && s_tutorgroup = '$tutorgroup'";
    $result = mysql_query ($sql);
    echo "Your activities have been updated.\n";
    }

    But it the new options submitted are not updated and reflected on the database.

    Please advice.

  • #4
    New Coder
    Join Date
    Jul 2003
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sorry..I know why it didn't get updated and reflected on the database just nw.

    A typo error in the table name.


  •  

    Posting Permissions

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