Problem inserting a function - Easy question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • zek2005

    #1

    Problem inserting a function - Easy question

    Hi !!!

    I have the following php code

    <?php
    $db = mysql_connect(" 1", user, password)
    or die ("can´t connect");
    mysql_select_db (efemerides,$db );
    mysql_close();
    ?>

    I receive the error "can´t connect". Right beacuse "1" is not my
    server.

    Then I insert a function in the code and I do not receive the "can´t
    connect" error. It seems that when I insert the function in the PHP
    doesn´t work as it should

    <?php
    $db = mysql_connect(" 1", user, password)
    or die ("no se ha podido conectar");
    mysql_select_db (efemerides,$db );
    function quitar($mensaje )
    {
    $mensaje = str_replace("<" ,"<",$mensaj e);
    $mensaje = str_replace(">" ,">",$mensaj e);
    $mensaje = str_replace("\' ","'",$mensaje) ;
    $mensaje = str_replace('\" ',""",$mensaje) ;
    $mensaje = str_replace("\\ \\","\",$mensaj e);
    return $mensaje;
    }
    mysql_close();
    ?>

    Any suggestion?

    Regards!

    Ezequiel

  • Rik

    #2
    Re: Problem inserting a function - Easy question

    zek2005 <esapoznik@gmai l.comwrote:
    Hi !!!
    Hello !!!
    I have the following php code
    >
    <?php
    $db = mysql_connect(" 1", user, password)
    or die ("can´t connect");
    mysql_select_db (efemerides,$db );
    mysql_close();
    ?>
    >
    I receive the error "can´t connect". Right beacuse "1" is not my
    server.
    >
    Then I insert a function in the code and I do not receive the "can´t
    connect" error. It seems that when I insert the function in the PHP
    doesn´t work as it should
    $mensaje = str_replace('\" ',""",$mensaje) ;
    This will result in a parse error, preventing the script from ever
    executing (which you would know if you had display_errors on, which is
    very handy in development).

    Change the line to the following and you'll get the expected behaviour:
    $mensaje = str_replace('\" ','"',$mensaje) ;
    --
    Rik Wasmus*

    Comment

    • Curtis

      #3
      Re: Problem inserting a function - Easy question

      On Sun, 04 Feb 2007 07:22:17 -0800, zek2005 <esapoznik@gmai l.comwrote:
      Hi !!!
      Greetings!!
      I have the following php code
      >
      <?php
      $db = mysql_connect(" 1", user, password)
      or die ("can´t connect");
      mysql_select_db (efemerides,$db );
      mysql_close();
      ?>
      >
      I receive the error "can´t connect". Right beacuse "1" is not my
      server.
      >
      Then I insert a function in the code and I do not receive the "can´t
      connect" error. It seems that when I insert the function in the PHP
      doesn´t work as it should
      >
      <?php
      $db = mysql_connect(" 1", user, password)
      "1" is not a valid host name. You should usually use "localhost"
      or die ("no se ha podido conectar");
      mysql_select_db (efemerides,$db );
      function quitar($mensaje )
      {
      $mensaje = str_replace("<" ,"<",$mensaj e);
      $mensaje = str_replace(">" ,">",$mensaj e);
      $mensaje = str_replace("\' ","'",$mensaje) ;
      $mensaje = str_replace('\" ',""",$mensaje) ;
      $mensaje = str_replace("\\ \\","\",$mensaj e);
      return $mensaje;
      }
      mysql_close();
      ?>
      Use PHP built-in escaping instead of making your own function:

      $safe = htmlentities(ge t_magic_quotes_ gpc() ? stripslashes($m ensaje) :
      $mensaje);
      <snip>
      --
      Curtis, http://dyersweb.com

      Comment

      Working...