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 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2008
    Posts
    92
    Thanks
    19
    Thanked 0 Times in 0 Posts

    AJAX and mysql_real_escape_string

    Hi, I have a webpage that uses jquery to send an input box data to a php file. The php file then inserts this data into the database and returns xml to the webpage which displays it.

    Code:
    <?php
    
    require("requires/database.php");
    
    foreach($_POST as $key => $value) $_POST[$key] = urldecode(trim($value)); //this was from a script I am modding so I am using it
    
    $name = mysql_real_escape_string("$_POST[$name]"); //to make sure it is ok before putting it in the database.
    
    header("Content-type: text/xml");
    echo "<?xml version='1.0' encoding='ISO-8859-1'?>";
    echo "<note>";
    echo '<message>'.$name.'</message>';
    echo "</note>";
    
    ?>

    I get this error: Error: uncaught exception: [object Object] when I use
    mysql_real_escape_string. If I use mysql_escape_string it works, but I read that this function shouldn't be used anymore.

    Any ideas?

    Thanks

  • #2
    New Coder
    Join Date
    Mar 2008
    Posts
    92
    Thanks
    19
    Thanked 0 Times in 0 Posts
    Fixed:

    require("requires/database.php");

    needed to be:

    require("database.php");

    mysql_real_escape_string needs a db connection I guess.

    Thanks anyways

  • #3
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    Quote Originally Posted by spetsacdc View Post
    mysql_real_escape_string needs a db connection I guess.
    Correct. It does require a db connection.


  •  

    Posting Permissions

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