posting multiple queries

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Geoff Berrow

    posting multiple queries

    This is puzzling.

    If I run

    $sql = "INSERT INTO customer
    (custid,usernam e,password,titl e,firstname,las tname,street,to wncity,postcode ,telno,mobile,e mail,glasses)
    VALUES
    ('$custid','$us ername','$passw ord','$title',' $firstname','$l astname','$stre et',
    '$towncity','$p ostcode','$teln o','$mobile','$ email','$glasse s')";INSERT
    INTO orders(custid,p id)VALUES('$cus tid','$pid')";

    $result = mysql_query($sq l);

    nothing happens.

    So I do a

    print "$sql";

    and copy the result into a phpmyadmin SQL window

    The query works just fine. Anyone know why?


    --
    Geoff Berrow
    It's only Usenet, no one dies.
    My opinions, not the committee's, mine.
    Simple RFDs http://www.ckdog.co.uk/rfdmaker/
  • MeerKat

    #2
    Re: posting multiple queries

    Geoff Berrow wrote:
    [color=blue]
    > This is puzzling.
    >
    > If I run
    >
    > $sql = "INSERT INTO customer
    > (custid,usernam e,password,titl e,firstname,las tname,street,to wncity,postcode ,telno,mobile,e mail,glasses)
    > VALUES
    > ('$custid','$us ername','$passw ord','$title',' $firstname','$l astname','$stre et',
    > '$towncity','$p ostcode','$teln o','$mobile','$ email','$glasse s')";INSERT
    > INTO orders(custid,p id)VALUES('$cus tid','$pid')";
    >
    > $result = mysql_query($sq l);[/color]

    at this point, see if mysql is generating any errors:
    if (mysql_error()) { print mysql_error(); }
    [color=blue]
    > nothing happens.
    >
    > So I do a
    >
    > print "$sql";
    >
    > and copy the result into a phpmyadmin SQL window
    >
    > The query works just fine. Anyone know why?
    >
    >[/color]

    --
    MeerKat

    Comment

    • MeerKat

      #3
      Re: posting multiple queries

      MeerKat wrote:
      [color=blue]
      > Geoff Berrow wrote:
      >[color=green]
      >> This is puzzling.
      >>
      >> If I run
      >> $sql = "INSERT INTO customer
      >> (custid,usernam e,password,titl e,firstname,las tname,street,to wncity,postcode ,telno,mobile,e mail,glasses)
      >>
      >> VALUES
      >> ('$custid','$us ername','$passw ord','$title',' $firstname','$l astname','$stre et',
      >>
      >> '$towncity','$p ostcode','$teln o','$mobile','$ email','$glasse s')";INSERT
      >> INTO orders(custid,p id)VALUES('$cus tid','$pid')";
      >>
      >> $result = mysql_query($sq l);[/color]
      >
      >
      > at this point, see if mysql is generating any errors:
      > if (mysql_error()) { print mysql_error(); }[/color]

      .... of course, it'll probably tell you you're doing two inserts in one
      which isn't allowed :)
      [color=blue][color=green]
      >> nothing happens.
      >>
      >> So I do a
      >> print "$sql";
      >>
      >> and copy the result into a phpmyadmin SQL window
      >>
      >> The query works just fine. Anyone know why?
      >>
      >>[/color]
      >[/color]

      --
      MeerKat

      Comment

      • Geoff Berrow

        #4
        Re: posting multiple queries

        I noticed that Message-ID:
        <qj2cb.3461$Fb2 .31286409@news-text.cableinet. net> from MeerKat contained
        the following:
        [color=blue][color=green]
        >> $result = mysql_query($sq l);[/color]
        >
        >at this point, see if mysql is generating any errors:
        > if (mysql_error()) { print mysql_error(); }[/color]

        You have an error in your SQL syntax near '; INSERT INTO
        orders(custid,p id)VALUES('P3C3 DsOVJwgAARBeGao ','1')' at line 1

        Query still runs fine in PHPMyAdmin

        --
        Geoff Berrow
        It's only Usenet, no one dies.
        My opinions, not the committee's, mine.
        Simple RFDs http://www.ckdog.co.uk/rfdmaker/

        Comment

        • Phil Roberts

          #5
          Re: posting multiple queries

          With total disregard for any kind of safety measures MeerKat
          <liquidlaughter 2000@blueyonder .co.uk> leapt forth and uttered:
          [color=blue]
          > Geoff Berrow wrote:
          >[color=green]
          >> This is puzzling.
          >>
          >> If I run
          >>
          >> $sql = "INSERT INTO customer
          >> (custid,usernam e,password,titl e,firstname,las tname,street,to wnci
          >> ty,postcode,tel no,mobile,email ,glasses) VALUES
          >> ('$custid','$us ername','$passw ord','$title',' $firstname','$l astn
          >> ame','$street',
          >> '$towncity','$p ostcode','$teln o','$mobile','$ email','$glasse s')"
          >> ;INSERT INTO orders(custid,p id)VALUES('$cus tid','$pid')";
          >>
          >> $result = mysql_query($sq l);[/color]
          >
          > at this point, see if mysql is generating any errors:
          > if (mysql_error()) { print mysql_error(); }
          >[color=green]
          >> nothing happens.
          >>
          >> So I do a
          >>
          >> print "$sql";
          >>
          >> and copy the result into a phpmyadmin SQL window
          >>
          >> The query works just fine. Anyone know why?
          >>
          >>[/color]
          >[/color]

          mysql_query() only accepts a single Query.

          --
          There is no signature.....

          Comment

          • Geoff Berrow

            #6
            Re: posting multiple queries

            I noticed that Message-ID:
            <Zq2cb.3482$yk2 .31473714@news-text.cableinet. net> from MeerKat contained
            the following:
            [color=blue][color=green]
            >> at this point, see if mysql is generating any errors:
            >> if (mysql_error()) { print mysql_error(); }[/color]
            >
            >... of course, it'll probably tell you you're doing two inserts in one
            >which isn't allowed :)[/color]

            Well one after the other. Which /should/ work. It works in phpMyAdmin.
            phpMyAdmin will even generate PHP code for it. But it doesn't work.
            --
            Geoff Berrow
            It's only Usenet, no one dies.
            My opinions, not the committee's, mine.
            Simple RFDs http://www.ckdog.co.uk/rfdmaker/

            Comment

            • Geoff Berrow

              #7
              Re: posting multiple queries

              I noticed that Message-ID: <Xns93FFE8F9D79 7Fphilroberts@2 16.196.97.132>
              from Phil Roberts contained the following:
              [color=blue]
              >mysql_query( ) only accepts a single Query.[/color]
              So is phpMyAdmin doing something clever then or is it using another
              function or what?

              --
              Geoff Berrow
              It's only Usenet, no one dies.
              My opinions, not the committee's, mine.
              Simple RFDs http://www.ckdog.co.uk/rfdmaker/

              Comment

              • MeerKat

                #8
                Re: posting multiple queries

                Geoff Berrow wrote:[color=blue]
                > I noticed that Message-ID: <Xns93FFE8F9D79 7Fphilroberts@2 16.196.97.132>
                > from Phil Roberts contained the following:
                >
                >[color=green]
                >>mysql_query () only accepts a single Query.[/color]
                >
                > So is phpMyAdmin doing something clever then or is it using another
                > function or what?[/color]

                The clever one :)

                --
                MeerKat

                Comment

                • Geoff Berrow

                  #9
                  Re: posting multiple queries

                  I noticed that Message-ID:
                  <31bcb.3748$Gc5 .33351723@news-text.cableinet. net> from MeerKat contained
                  the following:
                  [color=blue][color=green]
                  >> So is phpMyAdmin doing something clever then or is it using another
                  >> function or what?[/color]
                  >
                  >The clever one :)[/color]

                  Hmm.

                  I decided to RTFM. It says:

                  Note: The query string should not end with a semicolon.

                  Which it has to if using multiple queries.

                  One of the comments also says:

                  If you want a good multiple query function, just look at the source of
                  phpMyAdmin ; particularly read_dump.php . A bit longer than what is
                  above, but more solid I should imagine.

                  So it looks like you're right. But other than that one comment above
                  there is nothing in the manual about it (other than in the contributed
                  notes) considering that what I'm doing is perfectly valid SQL (AFAIK)



                  --
                  Geoff Berrow
                  It's only Usenet, no one dies.
                  My opinions, not the committee's, mine.
                  Simple RFDs http://www.ckdog.co.uk/rfdmaker/

                  Comment

                  • MeerKat

                    #10
                    Re: posting multiple queries

                    Geoff Berrow wrote:
                    [color=blue]
                    > I noticed that Message-ID:
                    > <31bcb.3748$Gc5 .33351723@news-text.cableinet. net> from MeerKat contained
                    > the following:
                    >
                    >[color=green][color=darkred]
                    >>>So is phpMyAdmin doing something clever then or is it using another
                    >>>function or what?[/color]
                    >>
                    >>The clever one :)[/color]
                    >
                    >
                    > Hmm.
                    >
                    > I decided to RTFM. It says:
                    >
                    > Note: The query string should not end with a semicolon.
                    >
                    > Which it has to if using multiple queries.
                    >
                    > One of the comments also says:
                    >
                    > If you want a good multiple query function, just look at the source of
                    > phpMyAdmin ; particularly read_dump.php . A bit longer than what is
                    > above, but more solid I should imagine.
                    >
                    > So it looks like you're right. But other than that one comment above
                    > there is nothing in the manual about it (other than in the contributed
                    > notes) considering that what I'm doing is perfectly valid SQL (AFAIK)[/color]

                    Well actually, if you think about it, it's never going to work with more
                    than one query. How would mysql_insert_id work if there were two
                    inserts? How would the mysql_fetch_xxx functions work if there were
                    multiple selects?

                    --
                    MeerKat

                    Comment

                    Working...