Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-04-2008, 12:57 AM   PM User | #1
elvn0
New Coder

 
Join Date: Feb 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
elvn0 is an unknown quantity at this point
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?
elvn0 is offline   Reply With Quote
Old 03-04-2008, 01:08 AM   PM User | #2
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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????? 
__________________
Fumigator is offline   Reply With Quote
Old 03-04-2008, 02:20 AM   PM User | #3
digitalfiz
New Coder

 
Join Date: Mar 2008
Location: Lakeland, FL
Posts: 39
Thanks: 1
Thanked 3 Times in 3 Posts
digitalfiz is an unknown quantity at this point
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.
digitalfiz is offline   Reply With Quote
Old 03-04-2008, 02:38 AM   PM User | #4
elvn0
New Coder

 
Join Date: Feb 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
elvn0 is an unknown quantity at this point
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?
elvn0 is offline   Reply With Quote
Old 03-04-2008, 02:55 AM   PM User | #5
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
What is line 7? Can we see the exact error? Is the error actually in config2.php or opendb.php?
__________________
Fumigator is offline   Reply With Quote
Old 03-04-2008, 03:02 AM   PM User | #6
elvn0
New Coder

 
Join Date: Feb 2008
Posts: 14
Thanks: 1
Thanked 0 Times in 0 Posts
elvn0 is an unknown quantity at this point
That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.
elvn0 is offline   Reply With Quote
Old 03-04-2008, 03:15 AM   PM User | #7
_Aerospace_Eng_
Supreme Master coder!


 
_Aerospace_Eng_'s Avatar
 
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light_Aerospace_Eng_ is a glorious beacon of light
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!||||
_Aerospace_Eng_ is offline   Reply With Quote
Old 03-04-2008, 03:53 AM   PM User | #8
Inigoesdr
Super Moderator


 
Inigoesdr's Avatar
 
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Inigoesdr is a jewel in the roughInigoesdr is a jewel in the roughInigoesdr is a jewel in the rough
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.
Inigoesdr is offline   Reply With Quote
Old 03-04-2008, 07:56 PM   PM User | #9
jlhaslip
Regular Coder

 
Join Date: Feb 2007
Location: Canada
Posts: 924
Thanks: 10
Thanked 56 Times in 55 Posts
jlhaslip is on a distinguished road
PHP Code:
include('config2.php');
include(
'opendb.php'); 
jlhaslip is offline   Reply With Quote
Old 03-04-2008, 08:24 PM   PM User | #10
Fumigator
UE Antagonizer


 
Fumigator's Avatar
 
Join Date: Dec 2005
Location: Utah, USA, Northwestern hemisphere, Earth, Solar System, Milky Way Galaxy, Alpha Quadrant
Posts: 7,686
Thanks: 42
Thanked 637 Times in 625 Posts
Fumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of lightFumigator is a glorious beacon of light
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.
__________________
Fumigator is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 05:29 PM.


Advertisement
Log in to turn off these ads.