Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1100161
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T00:50:23+00:00 2026-05-17T00:50:23+00:00

Im using the follow script to insert records into my DB: $sql = INSERT

  • 0

Im using the follow script to insert records into my DB:

$sql = "INSERT INTO fotetweets VALUES('$tweetid','$dp', '', '$username','$tag', '$twittercontent', '$twittertimestamp', '')";
mysql_query($sql);

However what if $twittercontent contains the ' char, I think it will fail. Correct?

If so how can I deal with it correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T00:50:24+00:00Added an answer on May 17, 2026 at 12:50 am

    You will want to look into mysql_real_escape_string. However, I would look into using the mysqli or PDO class instead and utilize prepared statements.

    EDIT

    Note, these can all be found / were pretty much taken from the PHP Manual under examples for prepared statements.

    Example Usage for MySQLi:

    <?php
    $mysqli = new mysqli("localhost", "my_user", "my_password", "my_database");
    
    /* check connection */
    if (mysqli_connect_errno()) {
        printf("Connect failed: %s\n", mysqli_connect_error());
        exit();
    }
    
    /* create a prepared statement */
    $stmt =  $mysqli->stmt_init();
    if ($stmt->prepare("INSERT INTO fotetweets VALUES(?, ?, '', ?, ?, ?, ?, '')")) {
        /* bind parameters for markers */
        $stmt->bind_param("issssi", $tweetid, $dp, $username, $tag, $twittercontent, $twittertimestamp);
    
        /* execute query */
        $stmt->execute();
    
        /* close statement */
        $stmt->close();
    }
    ?>
    

    Example Usage PDO:

    <?php
    $dsn = 'mysql:dbname=testdb;host=127.0.0.1';
    $user = 'dbuser';
    $password = 'dbpass';
    
    try {
        $dbh = new PDO($dsn, $user, $password);
    } catch (PDOException $e) {
        echo 'Connection failed: ' . $e->getMessage();
    }
    
    $sth = $dbh->prepare('INSERT INTO fotetweets VALUES(?, ?, '', ?, ?, ?, ?, '')');
    $sth->execute(array($tweetid, $dp, $username, $tag, $twittercontent, $twittertimestamp));
    ?>
    

    Example of mysql_real_escape_string usage:

    $tweetid = (int) $tweetid; // static cast to integer, if that is what it should be.
    $sql = "INSERT INTO fotetweets VALUES(
        $tweetid,'" . mysql_real_escape_string($dp) . "', 
        '', '" . mysql_real_escape_string($username) . "', 
        '" . mysql_real_escape_string($tag) . "', 
        '" . mysql_real_escape_string($twittercontent) . "', 
        '" . mysql_real_escape_string($twittertimestamp) . "', '')";
    

    You can find more information and extra usage examples at the manual pages listed above. Given I do know what $dp is I cannot tailor this exactly.

    SIDE NOTE

    This is all the assumption I am willing to make. The OP could be getting the data from POST and/or in an array form, or he could be getting it from a different means. Either or, given the example the OP posted, this is as accurate as I could be to tailor to the OP. If you have an issue or think it could be better explained / shown, well go ahead and add another answer which addresses it and not just another complaining comment remark about how no one does anything right when you are not willing to pony up the “correct” answer yourself.

    And of course if it is an array, this changes a lot of items and the OP should clear that up and not just random people making “guesses” as to where and how the data is being retrieved.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

im trying to insert an array values into the file using foreach.. and if
I understand that I can change a sql table using the follow sp: EXEC
Having follow the tutorial at http://mithin.in/2009/06/22/using-iphone-sdk-mapkit-framework-a-tutorial/ to integrate the MapKit into my application. However,
I am trying to execute a SQL script in my JUnit test using Spring.
I am using Action Script 3.0 to animate an instance (MovieClip class) to follow
I am using the follow code to get all text from a page into
I'm using the follow command to get a list of FileSystemInfo's IList<FileSystemInfo> requestFiles =
I would like to do the follow redirection using htaccess: From: http://www.mywebsite.com/home/?page_id=273&mnth=8&yr=1993 To: http://www.mywebsite.com/
I follow example from here using section listview http://lalit3686.blogspot.com/2012/05/sectionadapter.html But how can I implement
follow up: while I had already been using swfobject with static publishing, dynamic publishing

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.