SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: "For" problem

  1. #1
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    "For" problem

    The following code is not doing what I want it to do, in the script I'm using to produce the forms (I'm making a quiz program), it gives them names like fake11, fake21, fake31, answer1, then the second question is fake12 etc and 3rd is fake13 and so on. So to run the SQL I need to upload the fake answers and the real answer the user wants to add, I'm using the following code:

    PHP Code:
    $n $board_config['questions_quiz'];
    for ( 
    $i 0$i $n$i++ )
    {    
    $tehhardstuff "INSERT INTO phpbbtestboard_quiz_text (question, answer, quiz_enabled, game_id, fake1, fake2, fake3)
    VALUES
    ('" 
    $questeh "', '" $_POST["answer$i"] . "', '0', '" $tgi "', '" $_POST["fake1$i"] . "', '" $_POST["fake2$i"] . "', '" $_POST["fake3$i"] . "')";
    if( !
    $result $db->sql_query($tehhardstuff))
            {
            
    message_die(GENERAL_ERROR'Error updating Quiz Text Table.');
            }
        
            {
            
    message_die(GENERAL_MESSAGE'Quiz has uploaded successfully!');
            }
            

    But it doesn't work.. is there anything I can do so it will work? Thanks so much everyone

  2. #2
    Super Ninja Monkey Travis's Avatar
    Join Date
    Dec 2001
    Location
    Sioux City, Iowa
    Posts
    691
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Could you give some more info? "Doesn't work" doesn't tell us a whole lot. From a quick look I can tell you that
    PHP Code:
     {
            
    message_die(GENERAL_MESSAGE'Quiz has uploaded successfully!');
            } 
    needs to be
    PHP Code:
     else {
            
    message_die(GENERAL_MESSAGE'Quiz has uploaded successfully!');
            } 
    Travis Watkins - Hyperactive Coder
    My Blog: Realist Anew
    Projects: Alacarte - Gnome Menu Editor

  3. #3
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry, It adds a blank row to the database. It works fine except the fake1, fake2, fake3 and answer fields are not uploaded.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Leuven, Belgium
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Writing queries often gets messy - your method of using double quotes and leaving the variables inside might make things more difficult than it's worth - why don't you try:
    echo htmlspecialchars($tehhardstuff);
    echo '<br /><pre>'.print_r($_POST, TRUE).'</pre>';

    right after you've set $tehhardstuff ? That way you can also see if the element names are really matching up, and you can do whatever you need to with the query if that's not the case. If you still really can't get it, you can post these (minus the 'answer' output since that's irrelevant) here.

    On another security-minded note, you do need to be sure you've conditionally added slashes to those $_POST variables before you put them in a query like this. You do have single quotes around them, and that's good.

  5. #5
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks! The answers and fakes are now uploading but the question isn't uploaded

    i have an example here: http://www.cricketmx.com/testforum/v...hp?viewquiz=23

  6. #6
    Simulation Cricketer
    Join Date
    Sep 2004
    Location
    australia
    Posts
    470
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Oops, my bad, it works perfectly. Thanks!!

  7. #7
    SitePoint Enthusiast
    Join Date
    Feb 2003
    Location
    Leuven, Belgium
    Posts
    78
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    is this value showing up when you output the query? Your script needs to know what $questeh is - either you could hard-code this in somewhere, or put it in your form with the rest of the questions -
    <input type="hidden" name="questeh" value="Teh questeh is the hardstuff?"> - and then reference it in your query as $_POST['questeh'] instead of $questeh.

    <edit - see you've solved it - congrats! />


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
  •