SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Parse error!!!!! PLEASE HELP

    I don't know why PHP doesn't accept this.
    what I'm trying to do is ordering questions in a test, a form will show up with the questions and the user needs (if he wants) to enter the order (integer numbers).
    later on these numbers must be stored in the db.
    So far everything is working fine except storing into the db, I'm getting a parse error each time I tried to do so!!

    Here is the code

    - the form
    <html>
    <head>
    <title>Order your questions</title>
    </head>
    <body>
    <FORM NAME= "OrderForm" METHOD= POST ACTION= "order_preview.php">
    [ php ]<?
    mysql_connect("localhost","","") or die ("Unable to connect to database");
    mysql_select_db("test_toaster") or die ("Unable to select database test_toaster");
    //session
    $t_id = 2;
    $resultID= mysql_query("SELECT content,question.id FROM question,test_questions WHERE $t_id=test_id AND question_id=id");
    $max=mysql_num_rows($resultID);
    for ($num=0 ; $num <$max ; $num++)
    {
    $row = mysql_fetch_assoc($resultID);
    ?>
    <INPUT TYPE="TEXT" NAME="order[<?echo $row["id"];?>]" SIZE=2 MAXLENGTH=2> &nbsp;&nbsp;
    <?
    echo $row["content"],"<BR>";
    }
    ?>[/PHP]
    <INPUT TYPE="SUBMIT" NAME="Submit" VALUE="SAVE">
    </FORM>
    </body>
    </html>

    -----------------
    -the php script that will store the numbers
    PHP Code:
    <?
    $t_id
    =2;
    mysql_connect("localhost","","") or  die ("Unable to connect to database");
    mysql_select_db("test_toaster") or die ("Unable to select database test_toaster");
    $resultIDmysql_query("SELECT content,question.id FROM question,test_questions WHERE $t_id=test_id AND question_id=id");
    for (
    $num=$num mysql_num_rows($resultID) ; $num++)
    {
        
    $row mysql_fetch_assoc($resultID);
        if (
    $order[$row["id"]] != "")
        {
            
    $insert_order=mysql_query("UPDATE test_questions SET order_of_questions = '$order[$row["id"]]' WHERE '$row["id"]'=test_questions.question_id AND test_id=$t_id ");//the error occours in this line
            
    echo $row["content"];
            echo 
    $order[$row["id"]],"<BR>";
        }
    }
    ?>
    here is the message I got:
    parse error, expecting `']''

    Any help will be really appreciated.
    Last edited by lina2401; Apr 7, 2002 at 09:41.

  2. #2
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hi lina

    could you edit your post to include the code within [ php ] [ /php ] tags so that it's syntax-highlighted? and also post the exact error message (esp what line the error is)

    <<edit>> sorry i can't help now... i've gtg go off to watch a show... i'm sure someone else will come around and solve your problem (well, actually, provided you do as i said lol )
    Last edited by redemption; Apr 7, 2002 at 06:54.

  3. #3
    Action! filmfoto's Avatar
    Join Date
    Dec 2001
    Location
    Sweden
    Posts
    278
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: Parse error!!!!! PLEASE HELP

    Originally posted by lina2401
    PHP Code:
    $insert_order=mysql_query("UPDATE test_questions SET order_of_questions = '$order[$row["id"]]' WHERE '$row["id"]'=test_questions.question_id AND test_id=$t_id "); 

    Try changing this line to:
    PHP Code:
    $insert_order=mysql_query("UPDATE test_questions SET order_of_questions = '$order[{$row['id']}]' WHERE '{$row['id']}'=test_questions.question_id AND test_id=$t_id "); 

    Hope this helps,



    Cheers.

  4. #4
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    filmfoto,
    I tired what u suggested and I got this parse error :
    parse error,expecting 'T_STRING'or 'T_VARIABLE'or 'T_NUM_STRING'

    Any ideas on what does that mean??!!

  5. #5
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you can't use the $var['var'] with ANY quotes in a quoted area... double, or single...


    PHP Code:
    $insert_order=mysql_query("UPDATE test_questions SET order_of_questions='$order[$row[id]]' WHERE question_id.test_questions=$row[id] && test_id=$t_id"); 
    I've never used that . in a WHERE command, but that should work...

  6. #6
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    someonewhois,
    This time the old parse error appeared!!
    parse error, expecting `']''

  7. #7
    SitePoint Wizard silver trophy someonewhois's Avatar
    Join Date
    Jan 2002
    Location
    Canada
    Posts
    6,364
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    oh.

    oops, let's see...

    PHP Code:
    $insert_order mysql_query("UPDATE test_questions SET order_of_questions='$order['$row[id]']' WHERE question_id.test_questions=$row[id] && test_id=$t_id"); 
    You can try that or:

    PHP Code:
    $insert_order mysql_query("UPDATE test_questions SET order_of_questions='$order[$row['id']]' WHERE question_id.test_questions=$row[id] && test_id=$t_id"); 
    Who knows?


    Can you reallt do $order[$row[id]? :|

    Sorry,
    ~someonewhois

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2002
    Posts
    28
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Non of them worked!!

    you asked something about $order[$row[id]]!! what was it??

  9. #9
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Re: oh.

    altering somoonewhois's suggestion:
    PHP Code:
    $insert_order mysql_query("UPDATE test_questions SET order_of_questions='{$order[$row['id']]}' WHERE question_id.test_questions={$row['id']} && test_id=$t_id"); 
    one point to note: don't put quotes around your field values for your db only if they're integers...


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
  •