How to resolve this mysql error?

Discussion in 'PHP' started by hope2life, Aug 24, 2011.

  1. #1
    Hi,
    how can I resolve this mysql error? I dont understand this.

    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't compromise on their uptime performance over the net.
    Moreover they are ' at line 1


    Any idea?

    Thanks!
     
    hope2life, Aug 24, 2011 IP
  2. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #2
    It looks like the content your trying to load has apostrophes ' so and quick solution is to use addslashes() see the example below the surname O'Reilly

    
    <?php
    $str = "Is your name O'reilly?";
    
    echo addslashes($str);
    
    // Outputs: Is your name O\'reilly?
    ?>
    
    
    PHP:
    In order for use to help your further please post your mysql query
     
    MyVodaFone, Aug 24, 2011 IP
  3. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #3
    this is mysql query



    <?php
    $id=$_POST['id'];
    $cat1=$_POST['articlenumber'];
    $cat2=$_POST['articletitle'];

    $description=$_POST['description'];


    $file='rajesh.txt';

    if(!file_exists($file)){
    die("There is no file");
    }

    $fhh=fopen($file,'w') or die('Could not open file');
    fwrite($fhh,$description) or die('Could not write to file');
    $data=file_get_contents($file);


    include('connection.php');

    $query="SELECT * FROM businessarticles WHERE id='$id'";
    $result=mysql_query($query) or die('query failed');

    $row=mysql_fetch_array($result);






    $query1="UPDATE businessarticles SET articlenumber='$cat1', articletitle='$cat2', articlebody='$data' WHERE id='$id'";

    mysql_query($query1) or die(mysql_error());



    echo "<center>"."Entry successfully updated"."</center>";

    ?>
     
    hope2life, Aug 24, 2011 IP
  4. MyVodaFone

    MyVodaFone Well-Known Member

    Messages:
    1,048
    Likes Received:
    42
    Best Answers:
    10
    Trophy Points:
    195
    #4
    Might need tweaking
    
    $query1="UPDATE businessarticles SET articlenumber='$cat1', articletitle='"  . addslashes($cat2). "', articlebody='" . addslashes($data). "' WHERE id='$id'";
    
    Code (markup):
     
    MyVodaFone, Aug 24, 2011 IP
  5. hope2life

    hope2life Active Member

    Messages:
    1,641
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    90
    #5
    yes that was the problem of what u said. I understood now.

    Thanks for your help.
     
    hope2life, Aug 24, 2011 IP
  6. [GotHost] James

    [GotHost] James Guest

    Messages:
    17
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Just FYI, you should really use mysql_real_escape_string rather than addslashes for security and safety.
     
    [GotHost] James, Aug 24, 2011 IP
  7. JohnnySchultz

    JohnnySchultz Peon

    Messages:
    277
    Likes Received:
    4
    Best Answers:
    7
    Trophy Points:
    0
    #7
    it's better to use mysql_real_escape_string rather than addslashes..

    
    <?php
    $id=mysql_real_escape_string($_POST['id']);
    ...
    
    PHP:
     
    JohnnySchultz, Aug 24, 2011 IP
  8. ZeroGamma

    ZeroGamma Peon

    Messages:
    35
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #8
    We'll probably need more of your SQL query to help you there.

    EDIT: Seems others answered before I submitted my post. :/
     
    ZeroGamma, Aug 24, 2011 IP