1

My code, which archives old members from a membership database, when run, returns

You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'DELETE FROM members WHERE member_ref = 155' at line 5.

It should copy the entry to the identical 'archive' table from 'members' and delete the original in members.

$ref = '155';

$leave = mysql_query("  INSERT INTO archive 
                        SELECT *
                        FROM members
                        WHERE member_ref = ".$ref.";
                        DELETE FROM members
                        WHERE member_ref = ".$ref ) or die(mysql_error());

I know I should be using mysqli but I haven't had time to standardise the whole system (~120 pages) from mysql to mysqli.

It's parsing 155 into the second $ref

Using the phpmyadmin's SQL window and entering the following works perfectly.

INSERT INTO archive 
                        SELECT *
                        FROM members
                        WHERE member_ref = 155;
                        DELETE FROM members
                        WHERE member_ref = 155

What am I missing?

3
  • 4
    You cannot have two seperate queries in one statement. Unless you specify a different separator than the default one (;). Its best practice however to have one statement for one job. Commented Aug 1, 2015 at 18:24
  • @paskl you confuse me. ; is the separator, no? Commented Aug 1, 2015 at 18:25
  • 1
    See the manual, php.net/manual/en/function.mysql-query.php. mysql_query() sends a unique query (multiple queries are not supported) Commented Aug 1, 2015 at 18:28

2 Answers 2

2

Use Separate Call, like this, See Details About mysql_query

$leave = mysql_query("  INSERT INTO archive 
                        SELECT *
                        FROM members
                        WHERE member_ref = '$ref' ") or die(mysql_error());

$leave = mysql_query("  DELETE FROM members
                        WHERE member_ref = '$ref'") or die(mysql_error());
Sign up to request clarification or add additional context in comments.

Comments

0

If you go to the PHP Manual, it is written right on the first line:

mysql_query() sends a unique query (multiple queries are not supported)

http://php.net/manual/en/function.mysql-query.php

Therefore you should put your queries in separate mysql_query() calls.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.