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

Thread: Change Answer

  1. #1
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts

    Change Answer

    PHP Code:
    <br/>
    <form method="post" action="<?php $_SERVER['PHP_SELF'?>">
        Change the answer to 
        <select name="changeanswer_opinion">
            <option>For</option>
            <option>Against</option>
        </select>
        for the question 
        <select name="changeanswer_question">
    <?php

    $sql 
    mysql_query("SELECT * FROM questions");

    while(
    $row mysql_fetch_array($sql)){
    $changeanswer_questions $row['question'];
    ?>
            <option><?php echo $changeanswer_questions?></option>

    <?php
    }
    ?>
        
        </select>
        of the candidate
        <select name="changeanswer_candidate">
            <option><?php echo $selected_candidate?></option>
        </select>
        <input type="submit" name="change_opinion">
    </form>
        
    <?php

    $change_opinion 
    $_POST['change_opinion'];
    $changeanswer_opinion $_POST['changeanswer_opinion'];
    $changeanswer_question $_POST['changeanswer_question'];
    $changeanswer_candidate $candidate_id;

    if(isset(
    $change_opinion)){
    mysql_query("UPDATE answers SET answer='$changeanswer_opinion' WHERE question_id='$qID' AND candidate_id='$changeanswer_candidate'") or die(mysql_error());
    }

    ?>
    What I can't do is grab the id of the question selected as a option here so I can use it in the update query.

    <option><?php echo $changeanswer_questions; ?></option>

    Any ideas how would I grab the id of the question?

  • #2
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    echo $row['qid'];
    ?

  • #3
    New Coder
    Join Date
    Jun 2007
    Posts
    60
    Thanks
    7
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    echo $row['qid'];
    ?
    How do I link it with the selected question?

  • #4
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,043
    Thanks
    19
    Thanked 42 Times in 42 Posts
    PHP Code:
    while($row = mysql_fetch_array($sql)){
    $changeanswer_questions = $row['question'];
    ?>
            <option><?php echo $changeanswer_questions?></option>

    <?php
    echo "$row['qid']"// this corresponds to the question which is pulled from the db.
    }
    ?>
        
        </select>
        of the candidate
        <select name="changeanswer_candidate">
            <option><?php echo $selected_candidate?></option>
        </select>
        <input type="submit" name="change_opinion">
    </form>
        
    <?php

    $change_opinion 
    $_POST['change_opinion'];
    $changeanswer_opinion $_POST['changeanswer_opinion'];
    $changeanswer_question $_POST['changeanswer_question'];
    $changeanswer_candidate $candidate_id;

    if(isset(
    $change_opinion)){
    mysql_query("UPDATE answers SET answer='$changeanswer_opinion' WHERE question_id='$qID' AND candidate_id='$changeanswer_candidate'") or die(mysql_error());
    }

    ?>


  •  

    Posting Permissions

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