General Community > Scripting Help
Parse Error Problem
Oldiesmann:
I have encountered this really annoying parse error that I can't seem to get rid of no matter how hard I try. I have two nearly identical functions (identical except for one variable in certain spots), and keep getting "Parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in ...\comment.php on line 78". The only thing on that line is a MySQL query, and I can't get it to take this query even though it's similar to another one earlier on in the file and I'm not getting parse errors there, so I can't understand what's causing this one... This part of the code is supposed to insert the info into the database and then redirect the visitor to the comment they just entered on the comments page.
Here's an exceprt:
<?php
function CDComment()
{
$action=$_GET['action'];
// some MySQL queries here
// then we use if statements to determine what to do
// based on what $action is
else
{
$submit=mysql_query("INSERT INTO cdcomments (albumid, name, comments) VALUES ($_POST['albumid'], $_POST['name'], $_POST['comments'])") or database_error(__FILE__,__LINE__); // error occurs on this line somewhere
$query01=mysql_query("SELECT commentid FROM cdcomments");
$query02=mysql_num_rows($query01);
header("Location: " . "comment.php?action=view;album=".$cd."#"$query02);
exit;
}
} //end of function
[Unknown]:
<?php
function CDComment()
{
$action=$_GET['action'];
// some MySQL queries here
// then we use if statements to determine what to do
// based on what $action is
else
{
$submit=mysql_query("INSERT INTO cdcomments (albumid, name, comments) VALUES ($_POST[albumid], $_POST[name], $_POST[comments])") or database_error(__FILE__,__LINE__); // error occurs on this line somewhere
$query01=mysql_query("SELECT commentid FROM cdcomments");
$query02=mysql_num_rows($query01);
header("Location: comment.php?action=view;album=".$cd."#".$query02);
exit;
}
}
?>
You shouldn't use "$array['element']" because it's already in quotes... so, instead use "$array[element]". Of course, you shouldn't use interpolation either, it's slow :P.
-[Unknown]
Oldiesmann:
Uh... interpolation? What's that?
Parham:
--- Code: ---$string = 'something'
$newstring = "something $string"; //when the variable is substituted for it's value, we call that variable interpolation. This will now be "something something"
--- End code ---
PHP lesson 4 discusses this :D
Oldiesmann:
Oh.
Well, that got rid of the parse error... Now it says "fatal error: call to undefined function array() on line 30 in .../comment.php".
Navigation
[0] Message Index
[#] Next page
Go to full version