Enjoy an ad free experience by logging in. Not a member yet?
Register .
03-04-2008, 12:57 AM
PM User |
#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?
03-04-2008, 01:08 AM
PM User |
#2
UE Antagonizer
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
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?????
03-04-2008, 02:20 AM
PM User |
#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.
03-04-2008, 02:38 AM
PM User |
#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?
03-04-2008, 02:55 AM
PM User |
#5
UE Antagonizer
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
What is line 7? Can we see the exact error? Is the error actually in config2.php or opendb.php?
03-04-2008, 03:02 AM
PM User |
#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.
03-04-2008, 03:15 AM
PM User |
#7
Supreme Master coder!
Join Date: Dec 2004
Location: In a place far, far away...
Posts: 19,293
Thanks: 2
Thanked 1,044 Times in 1,020 Posts
Quote:
Originally Posted by
elvn0
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! ||||
03-04-2008, 03:53 AM
PM User |
#8
Super Moderator
Join Date: Mar 2007
Location: Florida, USA
Posts: 3,601
Thanks: 2
Thanked 397 Times in 390 Posts
Quote:
Originally Posted by
elvn0
That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.
Yeah, hence the error.
03-04-2008, 07:56 PM
PM User |
#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' );
03-04-2008, 08:24 PM
PM User |
#10
UE Antagonizer
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
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.
Jump To Top of Thread
Thread Tools
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
HTML code is Off
All times are GMT +1. The time now is 05:29 PM .
Advertisement
Log in to turn off these ads.