Forum Moderators: coopster

Message Too Old, No Replies

SQL Query help

         

bysonary

12:27 am on Feb 5, 2007 (gmt 0)

10+ Year Member



Hello again world

I have a slight problem with a line of my code, I am getting the following problem.

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/www/juttuffi/menuadd.php on line 16

I suspect this is my own fault I am experimenting with this piece of code and cant seam to stumble upon the correct way of doing it as I usually do, anyhow the code is below, its not very long.


<?php
include '/home/www/juttuffi/dbc.php';
$name = $_POST['pages'];
$menuname = $_POST['pname'];

$query1 = mysql_query("SELECT pid FROM tpages WHERE name='$name'");

if (mysql_numrows($query1) == 0)
{
echo "There is nothing in the database";
}
else
{
while ($row = mysql_fetch_array($query1,MYSQL_ASSOC))
{
[b][2]$query2 = mysql_query("INSERT INTO tmenu (name, pid) VALUES ('$menuname', '$row['pid']')");[/2][/b]
echo $query2;
}
}
mysql_close($dbc);
?>

I have highlighted the line of code which is causing the problem and my guess is the problem is to do with $row['pid']

can anyone help me out here I would be grateful.

mcavic

1:08 am on Feb 5, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can't say $row['pid'] inside another set of quotes, as it would be too complicated to parse.

Just set $pid = $row['pid'] first, then use $pid in the query.

ericjust

2:08 am on Feb 5, 2007 (gmt 0)

10+ Year Member



You can also enclose $row['pid'] in brackets and it will work fine. This is generally a good idea for any variables contained in a string.

$query2 = mysql_query("INSERT INTO tmenu (name, pid) VALUES ('{$menuname}', '{$row['pid']}')");