SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Var Declare

  1. #1
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Var Declare

    I have the following code
    PHP Code:
    //Check if they have enough credit for sms over 160 chars
    $numcount mb_strlen($message);
    if (
    $numcount 160)
    {
    $second_number 2;
    $cost $count $second_number;
    if (
    $cost $credits) {
    echo 
    $costerror;
    exit();
    }

    This keep showing Notice: Undefined variable: cost when it's not triggering the $costerror but works fine if the $costerror gets triggered.

    any way to stop php saying it's undefined.

  2. #2
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    where does $count come from?
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel

  3. #3
    SitePoint Wizard bronze trophy Jeff Mott's Avatar
    Join Date
    Jul 2009
    Posts
    1,314
    Mentioned
    19 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by txt3rob View Post
    Undefined variable: cost when it's not triggering the $costerror
    Presumably the error is coming from after the costerror if block. You'll have to show us that code. The small snippet you posted doesn't appear to have anything wrong with it.
    "First make it work. Then make it better."

  4. #4
    From space with love silver trophy
    SpacePhoenix's Avatar
    Join Date
    May 2007
    Location
    Poole, UK
    Posts
    5,072
    Mentioned
    103 Post(s)
    Tagged
    0 Thread(s)
    Just before the first bit of code that might fill $costerror add:

    PHP Code:
    $costerror=''
    That will setup $costerror as an empty string which will be filled by other code if there is an error
    Community Team Advisor
    Forum Guidelines: Posting FAQ Signatures FAQ Self Promotion FAQ
    Help the Mods: What's Fluff? Report Fluff/Spam to a Moderator

  5. #5
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by vectorialpx View Post
    where does $count come from?
    towards to the top of the script

    Code:
    $dbnumbers = $db->prepare('SELECT * FROM `numbers` WHERE `sent` = 0 AND `userid` = :id');
    $dbnumbers->bindParam(':id', $id, PDO::PARAM_INT);
    $dbnumbers->execute();
    $count = $dbnumbers->rowCount();

  6. #6
    SitePoint Addict bronze trophy vectorialpx's Avatar
    Join Date
    Dec 2012
    Location
    Bucharest
    Posts
    247
    Mentioned
    8 Post(s)
    Tagged
    0 Thread(s)
    @SpacePhoenix gave you the answer
    Be nice to nerds. Chances are you'll end up working for one - Bill Gates
    > photos | admin panel

  7. #7
    SitePoint Zealot txt3rob's Avatar
    Join Date
    Jul 2013
    Location
    Liverpool UK
    Posts
    199
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    it's fixed now thank you all for your input and help


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
  •