Syntax Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Call Me Tom

    Syntax Problem

    I have the following PHP/MySQL code segment

    $query2="UPDATE reports
    SET fsacars_rep_url = $url_new
    WHERE pilot_id = $pid";

    echo"$query2";

    $result2=mysql_ query($query2) or die(mysql_error ());

    The above code produces the following messages:

    The echo of the query shows:
    UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
    ~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2

    When the query runs the following error message is generated:
    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
    '://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at line
    2

    What is the proper syntax?

    Thanks,
    Tom
  • Jon Slaughter

    #2
    Re: Syntax Problem


    "Call Me Tom" <nobody@devnull .spamcop.netwro te in message
    news:z7q0i.9619 $pW5.3833@trndd c07...
    >I have the following PHP/MySQL code segment
    >
    $query2="UPDATE reports
    SET fsacars_rep_url = $url_new
    WHERE pilot_id = $pid";
    >
    echo"$query2";
    >
    $result2=mysql_ query($query2) or die(mysql_error ());
    >
    The above code produces the following messages:
    >
    The echo of the query shows:
    UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
    ~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2
    >
    When the query runs the following error message is generated:
    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
    '://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at
    line
    2
    >
    What is the proper syntax?
    >
    I don't know but my guess is that you need to put ' ' on your variables,

    $query2="UPDATE reports
    SET fsacars_rep_url = '$url_new'
    WHERE pilot_id = '$pid';";


    Comment

    • Schraalhans Keukenmeester

      #3
      Re: Syntax Problem

      At Wed, 09 May 2007 20:26:07 +0000, Call Me Tom let his monkeys type:
      I have the following PHP/MySQL code segment
      >
      $query2="UPDATE reports
      SET fsacars_rep_url = $url_new
      WHERE pilot_id = $pid";
      >
      echo"$query2";
      >
      $result2=mysql_ query($query2) or die(mysql_error ());
      >
      The above code produces the following messages:
      >
      The echo of the query shows:
      UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
      ~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2
      >
      When the query runs the following error message is generated:
      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
      '://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2' at line
      2
      >
      What is the proper syntax?
      >
      Thanks,
      Tom
      Tom,

      Using strings in MySQL queries, enclose them in quotes:

      $query2="UPDATE reports
      SET fsacars_rep_url = '$url_new'
      WHERE pilot_id = $pid";

      // add quotes around $pid as well if it's a character field, not if it's a
      numerical value in the db.

      HTH
      Sh

      Comment

      • Call Me Tom

        #4
        Re: Syntax Problem

        Schraalhans Keukenmeester <invalid@invali d.spamwrote in
        news:pan.2007.0 5.09.21.17.08.1 76700@invalid.s pam:
        At Wed, 09 May 2007 20:26:07 +0000, Call Me Tom let his monkeys type:
        >
        >I have the following PHP/MySQL code segment
        >>
        >$query2="UPDAT E reports
        > SET fsacars_rep_url = $url_new
        > WHERE pilot_id = $pid";
        >>
        >echo"$query2 ";
        >>
        >$result2=mysql _query($query2) or die(mysql_error ());
        >>
        >The above code produces the following messages:
        >>
        >The echo of the query shows:
        >UPDATE reports SET fsacars_rep_url = http://69.72.192.154/
        >~caa/caa/logbooks/no_rept.txt WHERE pilot_id = 2
        >>
        >When the query runs the following error message is generated:
        >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 '://69.72.192.154/~caa/caa/logbooks/no_rept.txt WHERE pilot_id =
        >2' at line 2
        >>
        >What is the proper syntax?
        >>
        >Thanks,
        >Tom
        >
        Tom,
        >
        Using strings in MySQL queries, enclose them in quotes:
        >
        $query2="UPDATE reports
        SET fsacars_rep_url = '$url_new'
        WHERE pilot_id = $pid";
        >
        // add quotes around $pid as well if it's a character field, not if
        it's a numerical value in the db.
        >
        HTH
        Sh
        >
        Thanks. That solved the problem.

        Tom

        Comment

        • Toby A Inkster

          #5
          Re: Syntax Problem

          Call Me Tom wrote:
          Thanks. That solved the problem.
          But it will cause another (when $new_url contains a quote mark!)

          This should be (more or less) indestructible:

          $q2 = sprintf("UPDATE reports SET fsacars_rep_url ='%s' WHERE pilot_id=%d;",
          mysql_real_esca pe_string($url_ new),
          (int)$pid);

          --
          Toby A Inkster BSc (Hons) ARCS
          Fast withdrawal casino UK 2025 – Play now & cash out instantly! Discover the top sites for rapid, secure payouts with no delays.

          Geek of ~ HTML/SQL/Perl/PHP/Python/Apache/Linux

          Comment

          Working...