...

View Full Version : What is wrong with this query?



elvn0
03-04-2008, 12:57 AM
$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?

Fumigator
03-04-2008, 01:08 AM
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 {} (http://us3.php.net/manual/en/language.types.string.php#language.types.string.parsing) due to their complexity.



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

digitalfiz
03-04-2008, 02:20 AM
Or you can do this:




$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.

elvn0
03-04-2008, 02:38 AM
<?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?

Fumigator
03-04-2008, 02:55 AM
What is line 7? Can we see the exact error? Is the error actually in config2.php or opendb.php?

elvn0
03-04-2008, 03:02 AM
That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.

_Aerospace_Eng_
03-04-2008, 03:15 AM
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.

Inigoesdr
03-04-2008, 03:53 AM
That's the exact error. Line 7 is config2.php. There is nothing wrong in that file.
Yeah, hence the error. :p

jlhaslip
03-04-2008, 07:56 PM
include('config2.php');
include('opendb.php');

Fumigator
03-04-2008, 08:24 PM
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.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum