Page 1 of 1
I don't get it....
Posted: Sun Nov 30, 2003 12:12 pm
by Nay
heh, I've been working all day on this, my brain's probably burnt out. Here's the snippet:
Code: Select all
Elseif($mode == "post"):
$title = $_POST['title'];
$blog = $_POST['blog'];
if(empty($blog) || empty($title)):
echo "You need to fill in <strong>all</strong> fields.
EndIf;
$blog = unformat($blog);
$query = "INSERT INTO nl_blogs (title, blog, timestamp) VALUES ('$title', '$blog', NOW())";
$result = $mysql->query($query);
if(empty($result)):
echo "Failed to post";
exit;
EndIf;
header("Location: nl_blogs.php");
Elseif($mode == "delete"):
I get:
Parse error: parse error, unexpected T_STRING, expecting ',' or ';' in c:\appserv\www\nlogger\nl_blogs.php on line 119
Line 119 is the $query. If I put it into heredoc, then I get the same error except on line 125 which is the echo.
Any Idea?
-Nay
Posted: Sun Nov 30, 2003 12:14 pm
by Nay
Okay, after I saw that highlighting, I added the "; after the first echo and now I get this:
Code: Select all
Elseif($mode == "edit"):
include $path . "/templates/nl_header.php";
include $path . "/templates/nl_footer.php";
Elseif($mode == "post"):
$title = $_POST['title'];
$blog = $_POST['blog'];
if(empty($blog) || empty($title)):
echo "You need to fill in <strong>all</strong> fields.";
EndIf;
$blog = unformat($blog);
$query = "INSERT INTO nl_blogs (title, blog, timestamp) VALUES ('$title', '$blog', NOW())";
$result = $mysql->query($query);
if(empty($result)):
echo "Failed to post";
exit;
EndIf;
header("Location: nl_blogs.php");
Elseif($mode == "delete"):
And now I get:
Parse error: parse error, unexpected T_VARIABLE, expecting '{' in c:\appserv\www\nlogger\includes\functions.php on line 106
106 is the space between:
Code: Select all
include $path . "/templates/nl_header.php";
include $path . "/templates/nl_footer.php";
O_o
-Nay
Posted: Sun Nov 30, 2003 12:33 pm
by d3ad1ysp0rk
why aren't your if-else statements arranged like this..?
Code: Select all
if($var=="value1"){
do something
}
else if($var=="value2"){
do something else
}
else {
echo "you must fil in var!";
}
and what does the header include have in it?
Posted: Sun Nov 30, 2003 12:42 pm
by mchaggis
I could be you've missed another double quote further up the script? As I can't see anything wrong with those lines, and if it was a problem with the includes ud at least get a different error?
What editor are you using, does it have syntax highlighting.
These kinds of problems are the worse, spot the missing character in the middle of hundreds of other chars. Syntax highlighting will help you with missing quote (like it did with your initial prob), but you just try finding a missing ; lol
Posted: Sun Nov 30, 2003 7:46 pm
by Nay
I still can't let go of the lovely Notepad of gEdit. Ahh yes. I can't seem to find something as fast loading as it. Yes, I'm impatient. Anyhow, so there's no syntax highlighting. Though I wish Zend Studio was a little more in my budget. Sure US$195, but convert it here, it goes ~S$300 and with S$300 I could probably buy myself a new nice handphone lol heh.
LiLpunkSkateR: This is more of VB style coding, it's less confusing imho since } can end a loop, if, function - almost anything. Example:
Code: Select all
function bla {
while($i = 0; $ < 10; $i++) {
if($i == 5) {
echo $i;
} elseif ($i == 9) {
echo $i;
} else {
// do nothing
}
}
}
Now, that seems okay but to me, it can get a little chaotic over hundreds of lines of scripts. So I'd do it this way:
Code: Select all
function bla {
For($i = 0; $ < 10; $i++):
If($i == 5):
echo $i;
ElseIf($i == 9):
echo $i;
Else:
// do nothing
EndIf;
EndFor;
}
I actually saw this off Zend O_o

.
-Nay
Posted: Sun Nov 30, 2003 8:04 pm
by d3ad1ysp0rk
Nay wrote:I still can't let go of the lovely Notepad of gEdit. Ahh yes. I can't seem to find something as fast loading as it. Yes, I'm impatient. Anyhow, so there's no syntax highlighting. Though I wish Zend Studio was a little more in my budget. Sure US$195, but convert it here, it goes ~S$300 and with S$300 I could probably buy myself a new nice handphone lol heh.
LiLpunkSkateR: This is more of VB style coding, it's less confusing imho since } can end a loop, if, function - almost anything. Example:
Code: Select all
function bla {
while($i = 0; $ < 10; $i++) {
if($i == 5) {
echo $i;
} elseif ($i == 9) {
echo $i;
} else {
// do nothing
}
}
}
Now, that seems okay but to me, it can get a little chaotic over hundreds of lines of scripts. So I'd do it this way:
Code: Select all
function bla {
For($i = 0; $ < 10; $i++):
If($i == 5):
echo $i;
ElseIf($i == 9):
echo $i;
Else:
// do nothing
EndIf;
EndFor;
}
I actually saw this off Zend O_o

.
-Nay
check out [google]winsyntax[/google], it loads just as fast as notepad, and has syntax highlighting and line numbering (the only two needed features with PHP coding IMO)
Posted: Mon Dec 01, 2003 12:58 am
by Nay
Heh, thanks...
The syntax seems okay, I just hate the spacings O_____O. *goes into registry and edits stuff*. Oh great, I'm going to have to re-install.
Anyway, I got it solved, It wasn't this file, I was missing another ; in the functions.php. <___<
-Nay
Posted: Mon Dec 01, 2003 9:48 am
by McGruff
Quick note: a better way to check if values have been entered in fields is to check if isset($_POST['var']) and also trim($_POST['var'] == '').
If you had an order form and someone entered a "0" for the number of products, empty() would produce a misleading result.
Posted: Mon Dec 01, 2003 10:34 am
by RTT
McGruff wrote:Quick note: a better way to check if values have been entered in fields is to check if isset($_POST['var']) and also trim($_POST['var'] == '').
If you had an order form and someone entered a "0" for the number of products, empty() would produce a misleading result.
you beat me to saying that
