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 10 of 10
  1. #1
    New Coder
    Join Date
    Feb 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts

    What is wrong with this query?

    Code:
    $query="INSERT INTO members (name, rank, pos, tod) 
    VALUES ('$_POST['name']', '$_POST['rank']', '$_POST['pos']', '$row['body']')";
    I get a syntax error. Can someone tell me what it is?

  • #2
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    Is this a quiz? You provide as little information as possible and we try to guess what's wrong?

    Anyways do an echo $query and see if any of your variables are empty. My guess at the problem is those imbedded variables aren't being parsed because they need to be enclosed in squiggly brackets {} due to their complexity.

    PHP Code:
    $query="INSERT INTO members (name, rank, pos, tod) 
    VALUES ('{$_POST['name']}', '{$_POST['rank']}', '{$_POST['pos']}', '{$row['body']}')"
    ;
    echo 
    $query//WHAT IS THE RESULT????? 

  • #3
    New Coder
    Join Date
    Mar 2008
    Location
    Lakeland, FL
    Posts
    39
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Or you can do this:

    PHP Code:

    $query
    ="INSERT INTO members (name, rank, pos, tod) VALUES
     ('"
    .$_POST['name']."', '".$_POST['rank']."', '".$_POST['pos']."', '".$row['body']."')"
    Which makes it a bit more obvisous as to whats going on in a syntax highlighted editor. it is the way I prefer to use when doing queries with variables in them.

  • #4
    New Coder
    Join Date
    Feb 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    PHP Code:
    <?php 

            
            
    include 'config2.php';
            include 
    'opendb.php';
            
    $query "SELECT * FROM XXX WHERE ID_TOPIC='237'"
         
            
    $result mysql_query($query) or die(mysql_error());

            
            while(
    $row mysql_fetch_array$result )) {

            
    $row['body'];
            
    $query="INSERT INTO members (name, rank, pos, tod) VALUES
     ('"
    .$_POST['name']."', '".$_POST['rank']."', '".$_POST['pos']."', '".$row['body']."')"


        
    mysql_query($query) or die('Error, insert query failed');
        echo 
    "Member added";
            

    ?>
    here is the whole thing.
    It gets the inputs from the another page using forms.

    now, i'm getting this problem
    Parse error: syntax error, unexpected T_INCLUDE on line 7. What am i doing wrong?

  • #5
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    What is line 7? Can we see the exact error? Is the error actually in config2.php or opendb.php?

  • #6
    New Coder
    Join Date
    Feb 2008
    Posts
    14
    Thanks
    1
    Thanked 0 Times in 0 Posts
    That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.

  • #7
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Quote Originally Posted by elvn0 View Post
    That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.
    And you would know this how? Please post config2.php with your database info changed.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by elvn0 View Post
    That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.
    Yeah, hence the error.

  • #9
    Regular Coder
    Join Date
    Feb 2007
    Location
    Canada
    Posts
    924
    Thanks
    10
    Thanked 56 Times in 55 Posts
    PHP Code:
    include('config2.php');
    include(
    'opendb.php'); 

  • #10
    UE Antagonizer Fumigator's Avatar
    Join Date
    Dec 2005
    Location
    Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
    Posts
    7,691
    Thanks
    42
    Thanked 637 Times in 625 Posts
    The parenthesis are optional.

    What I was asking the OP is if the parse error could be inside one of the included files, and posting the entire error would tell us that.


  •  

    Posting Permissions

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