SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    single quote error.

    hello. I just recently learned this code:
    Code:
    <HTML>
    <HEAD>
    <TITLE></TITLE>
    </HEAD>
    <BODY>
    PHP Code:
    <?php//connect to the databaseif (! @mysql_connect('localhost''username''password')) {die ('for some reason you cannot connect to the database');}//select the jokes tableif (! @mysql_select_db('jokes')) {die ("you can't find the jokes table" );}//create a mysql queryif (isset($_POST['submitjoke'])) {$joketext $_POST['joketext'];$sql "INSERT INTO jokes SETJokeText='$joketext',JokeDate=CURDATE()";if (@mysql_query($sql)) {echo('<P>your joke has been added!</P>');}else {echo ('<P>Error in submitting joke:' mysql_error() . '</P>');}}?>
    <form action="
    PHP Code:
    <?$_SERVER['PHP_SELF']?>
    " method="post"> Please submit a joke: <BR> <textarea cols="40" rows="10" name="joketext" wrap></textarea> <BR> <input type="submit" value="submit" name="submitjoke"> </form> </BODY> </HTML>
    every thing seems fine except when I submit anything in the textarea box with a apostrope. For example If I submit:
    Knock knock. Who' there?
    I get this error:
    Error in submitting joke:You have an error in your SQL syntax near 's there?', JokeDate=CURDATE()' at line 2
    when I don't use the apostrophe:

    knock knock. whos there.

    everything comes out fine. How do I allow people to use that apostrophe in the textarea box without getting this error?
    Last edited by jive; May 13, 2003 at 18:01.

  2. #2
    ********* Genius Mike's Avatar
    Join Date
    Apr 2001
    Location
    Canada
    Posts
    5,458
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $sql "INSERT INTO jokes
    SET
    JokeText='" 
    addslashes($joketext) . "',
    JokeDate=CURDATE()"

    Mike
    It's not who I am underneath, but what I do that defines me.

  3. #3
    SitePoint Addict
    Join Date
    Mar 2003
    Location
    Greenville, SC
    Posts
    388
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    awsome! thanks - works like a charm.


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
  •