I don't get it....

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

I don't get it....

Post 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
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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?
User avatar
mchaggis
Forum Contributor
Posts: 150
Joined: Mon Mar 24, 2003 10:31 am
Location: UK

Post 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
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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 :D.

-Nay
d3ad1ysp0rk
Forum Donator
Posts: 1661
Joined: Mon Oct 20, 2003 8:31 pm
Location: Maine, USA

Post 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 :D.

-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)
Nay
Forum Regular
Posts: 951
Joined: Fri Jun 20, 2003 11:03 am
Location: Brisbane, Australia

Post 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
McGruff
DevNet Master
Posts: 2893
Joined: Thu Jan 30, 2003 8:26 pm
Location: Glasgow, Scotland

Post 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.
RTT
Forum Commoner
Posts: 38
Joined: Thu Jul 17, 2003 10:22 am
Location: Wolverhampton, UK
Contact:

Post 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 8)
Post Reply