SitePoint Sponsor

User Tag List

Results 1 to 13 of 13
  1. #1
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Function problem...

    Whilst working on my CMS project, I came to a dilemma updating my post script. Where once I only allowed the news to be posted to one section, I wanted one form to be used for filling out news for various sections...

    PHP Code:
    <?php
    // post_functions.php

    function post_article($where) {
    global 
    $where;
    ...
    ?>
    ...
    <input type="hidden" name="cid" value="<?php echo $where?>">
    ...
    ?>
    PHP Code:
    if (isset($where)) {
    post_article($where);
    }
    ... 



    When I do this, I get the good ol' parse error on the "post_article($where);" Warum?

  2. #2
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    well, what is the function doing? is it returning a value?
    I'm pretty rusty, but i don't think you can just "run" a function like that.
    Like, i think you need to do

    $something = post_article($where);

    again, i'm probably wrong, but it's worth a shot.
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  3. #3
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    function post_article($where) {
    global $where;
    ...
    ?>
    ...
    <input type="hidden" name="cid" value="<?php echo $where?>">
    ...
    ?>
    if your function is defined like that then you forgot to jump back into php with the <?php tag... but i guess not though...

    you can use your function without returning (it's called a "method" in this case... but you guys prolly know that) though... probably you could post the exact error message as well as the line it's appearing at...
    Last edited by redemption; Mar 17, 2002 at 06:29.

  4. #4
    SitePoint Wizard Defender1's Avatar
    Join Date
    Apr 2001
    Location
    My Computer
    Posts
    2,808
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    not to mention there's no closing }
    Defender's Designs
    I'm Getting Married!

    Not-so-patiently awaiting Harry Potter Book 7 *sigh*

  5. #5
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Guys, all of that's in the code, but I left it out to spare you all.

    It was a basic parse error on line 9 (the line with the post_article($where) in the separate file).

    Basically, the function is called in post_functions.php and then used in post.php. But it ain't really working...

    PHP Code:
    <?php
    // post_functions.php
    ...
    function 
    post_article($where) {
    global 
    $where;
    if (isset(
    $pm_submit)) {
    $record mysql_query("INSERT INTO news (aid,cid,title,body,time,date,pic)".
    "VALUES ('$aid','$cid','$title','$body','$time','$date','$pic')");
    if (!
    $record) {
    echo 
    "SOMETHING WENT WRONG!!!";
    showfooter();
    exit;
    }
    } else {
    ?>
    <FORM method="post" action="<?php echo $PHP_SELF?>">
    <table width="450" border="0" cellspacing="0" cellpadding="2"><tr>
    ....
    ....
    <input type="hidden" name="cid" value="<?php echo $where?>">
    ...
    <?php
    }

    PHP Code:
    <?php
    // post.php

    showheader();
    if (!isset(
    $where)) {
    echo 
    "Poop!";
    showfooter();
    exit;
    } else {
    post_article($where};
    }
    showfooter();
    ?>

  6. #6
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ya'know, on second thought... I don't even need to use this as a function...

    Anyway, I'd still like to find out what I was doing wrong so that I don't do it again in the future...

  7. #7
    SitePoint Guru
    Join Date
    Mar 2002
    Posts
    608
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    post_article($where};
    should be
    post_article($where);

    What line is the error?

    Thanks

  8. #8
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ... it is ) instead of }.

    The error is on the line in post.php with post_article($where); for the 5 millionth time.

  9. #9
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you look at your code

    } else {
    post_article($where};
    }


    post_atricle($where};
    is wrong, the closing Parinthasis is a }curly brace

    Change it to ) instead of }

    GC
    Wanna be php coder!

  10. #10
    SitePoint Enthusiast gcarlyle's Avatar
    Join Date
    Mar 2002
    Location
    Olympia Wa
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    BTW It is wrong I copied and pasted this from the code you supplied above.

    } else {
    post_article($where};
    }


    GC
    Wanna be php coder!

  11. #11
    SitePoint Wizard silver trophy redemption's Avatar
    Join Date
    Sep 2001
    Location
    Singapore
    Posts
    5,269
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by Mike McT
    Guys, all of that's in the code, but I left it out to spare you all.
    great! which is why i said:
    if your function is defined like that then you forgot to jump back into php with the <?php tag... but i guess not though...
    anyway, it really is a brace ('}') instead of a parentheses (')')... if it isn't then please go change your code in your post to reflect what you actually have in your script

  12. #12
    SitePoint Zealot
    Join Date
    Mar 2002
    Location
    Perth, Australia
    Posts
    157
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You haven't left off the ending semi-colon from line 8 have you?
    Paul Davey
    webmaster for Whitford Church of Christ

  13. #13
    SitePoint Member
    Join Date
    Jan 2002
    Posts
    22
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Holy poop! So it is a curly brace. I HATE THE CURLY BRACE! IT IS MY ENEMY!




    -Mike


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •