By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,187 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,187 IT Pros & Developers. It's quick & easy.

posting multiple queries

P: n/a
This is puzzling.

If I run

$sql = "INSERT INTO customer
(custid,username,password,title,firstname,lastname ,street,towncity,postcode,telno,mobile,email,glass es)
VALUES
('$custid','$username','$password','$title','$firs tname','$lastname','$street',
'$towncity','$postcode','$telno','$mobile','$email ','$glasses')";INSERT
INTO orders(custid,pid)VALUES('$custid','$pid')";

$result = mysql_query($sql);

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/
Jul 17 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Geoff Berrow wrote:
This is puzzling.

If I run

$sql = "INSERT INTO customer
(custid,username,password,title,firstname,lastname ,street,towncity,postcode,telno,mobile,email,glass es)
VALUES
('$custid','$username','$password','$title','$firs tname','$lastname','$street',
'$towncity','$postcode','$telno','$mobile','$email ','$glasses')";INSERT
INTO orders(custid,pid)VALUES('$custid','$pid')";

$result = mysql_query($sql);
at this point, see if mysql is generating any errors:
if (mysql_error()) { print mysql_error(); }
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?


--
MeerKat

Jul 17 '05 #2

P: n/a
MeerKat wrote:
Geoff Berrow wrote:
This is puzzling.

If I run
$sql = "INSERT INTO customer
(custid,username,password,title,firstname,lastname ,street,towncity,postcode,telno,mobile,email,glass es)

VALUES
('$custid','$username','$password','$title','$firs tname','$lastname','$street',

'$towncity','$postcode','$telno','$mobile','$email ','$glasses')";INSERT
INTO orders(custid,pid)VALUES('$custid','$pid')";

$result = mysql_query($sql);

at this point, see if mysql is generating any errors:
if (mysql_error()) { print mysql_error(); }


.... of course, it'll probably tell you you're doing two inserts in one
which isn't allowed :)
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?


--
MeerKat

Jul 17 '05 #3

P: n/a
I noticed that Message-ID:
<qj*********************@news-text.cableinet.net> from MeerKat contained
the following:
$result = mysql_query($sql);


at this point, see if mysql is generating any errors:
if (mysql_error()) { print mysql_error(); }


You have an error in your SQL syntax near '; INSERT INTO
orders(custid,pid)VALUES('P3C3DsOVJwgAARBeGao','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/
Jul 17 '05 #4

P: n/a
With total disregard for any kind of safety measures MeerKat
<li****************@blueyonder.co.uk> leapt forth and uttered:
Geoff Berrow wrote:
This is puzzling.

If I run

$sql = "INSERT INTO customer
(custid,username,password,title,firstname,lastname ,street,townci
ty,postcode,telno,mobile,email,glasses) VALUES
('$custid','$username','$password','$title','$firs tname','$lastn
ame','$street',
'$towncity','$postcode','$telno','$mobile','$email ','$glasses')"
;INSERT INTO orders(custid,pid)VALUES('$custid','$pid')";

$result = mysql_query($sql);


at this point, see if mysql is generating any errors:
if (mysql_error()) { print mysql_error(); }
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?


mysql_query() only accepts a single Query.

--
There is no signature.....
Jul 17 '05 #5

P: n/a
I noticed that Message-ID:
<Zq*********************@news-text.cableinet.net> from MeerKat contained
the following:
at this point, see if mysql is generating any errors:
if (mysql_error()) { print mysql_error(); }


... of course, it'll probably tell you you're doing two inserts in one
which isn't allowed :)


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/
Jul 17 '05 #6

P: n/a
I noticed that Message-ID: <Xn*************************@216.196.97.132>
from Phil Roberts contained the following:
mysql_query() only accepts a single Query.

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/
Jul 17 '05 #7

P: n/a
Geoff Berrow wrote:
I noticed that Message-ID: <Xn*************************@216.196.97.132>
from Phil Roberts contained the following:

mysql_query() only accepts a single Query.


So is phpMyAdmin doing something clever then or is it using another
function or what?


The clever one :)

--
MeerKat

Jul 17 '05 #8

P: n/a
I noticed that Message-ID:
<31*********************@news-text.cableinet.net> from MeerKat contained
the following:
So is phpMyAdmin doing something clever then or is it using another
function or what?


The clever one :)


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/
Jul 17 '05 #9

P: n/a
Geoff Berrow wrote:
I noticed that Message-ID:
<31*********************@news-text.cableinet.net> from MeerKat contained
the following:

So is phpMyAdmin doing something clever then or is it using another
function or what?


The clever one :)

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)


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

Jul 17 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.