Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts

    what does this mean?

    Code:
    function mysql_fatal_error($msg)
    {
    $msg2 - mysql_error();
    echo <<< _END
    We are sorry, but it was not possible to complete
    the requested task. The error message we got was:
    <p>$msg: $msg2</p>
    Please click the back button on your browser
    and try again. If you are still having problems,
    please <a href="mailto:admin@server.com">email
    our administrator</a>. Thank you.
    _END;
    }
    i konw this is more user-friendly error messages on a production
    server.but i don't know the line "$msg2 - mysql_error();"meaning?who can explain it for me.thank you!
    Last edited by runeveryday; 09-11-2009 at 10:03 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2009
    Location
    Mansfield, Nottinghamshire, UK
    Posts
    1,555
    Thanks
    57
    Thanked 148 Times in 147 Posts
    $msg2 and $msg will be two separate pieces of data sent along with a form or process previous to that script, in case there is an error.

    mysql_error() is sent back from the server, as in a global carrier of mySQL errors.
    Last edited by Phil Jackson; 09-11-2009 at 09:05 AM.

  • #3
    Regular Coder
    Join Date
    Jul 2009
    Posts
    152
    Thanks
    8
    Thanked 0 Times in 0 Posts
    if the connection is fail,what is the result and the value of the variable $msg2 ,$msg ?if i use the parameter $msg . and how to use the function ? is the following right?
    Code:
    <?php
    $db_server=mysql_connect($db_hostname,$db_username,$db_password);
    if(!$db_server) 
    function mysql_fatal_error($msg)
    Last edited by runeveryday; 09-11-2009 at 10:14 AM.

  • #4
    New to the CF scene
    Join Date
    May 2010
    Posts
    2
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Code:
    $msg2 - mysql_error();
    lol dude it's a typo. You're using the animal guide book right?

    You can debug it too. I'll take it step by step after ward.

    It's suppose to be;

    Code:
    $msg2 = mysql_error();
    Debug:
    Code:
    echo <<< _END
    We are sorry, but it was not possible to complete
    the requested task. The error message we got was:
    <p>$msg: $msg2</p>
    Please click the back button on your browser
    and try again. If you are still having problems,
    please <a href="mailto:admin@server.com">email
    our administrator</a>. Thank you.
    _END;

    If you read the message you can see there's 2 variables in there and the bold variable is the hint that it suppose to be an assignment operator.


    I know this is an old thread but I was looking to see how to use this function. I sort of got it but now I need to suppress the warning.

    Anyway here's how you suppose to use it:

    PHP Code:
    <?php
    //Example 10-2. Connecting to a MySQL database
    require_once 'bad_login.php';
    $db_server = @mysql_connect($db_hostname$db_username$db_password);
    if (!
    $db_server) die(mysql_fatal_error("Unable to connect to MySQL: " ));
    function 
    mysql_fatal_error($msg)
    {
    $msg2 mysql_error();
    echo <<< _END
    We are sorry, but it was not possible to complete
    the requested task. The error message we got was:
    <p>$msg: $msg2</p>
    Please click the back button on your browser
    and try again. If you are still having problems,
    please <a href="mailto:admin@server.com">email
    our administrator</a>. Thank you.
    _END;
    }
    ?>
    The
    PHP Code:

    suppresses the mysql function warning.


    Here's the errata pages for the book:
    http://oreilly.com/catalog/errata.cs...=9780596157142
    Last edited by digitalzombie; 05-03-2010 at 07:45 PM.


  •  

    Posting Permissions

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