对两个不同的表使用两个insert语句

I would like to use two different insert statements with two different tables such as

<?
mysql_query("INSERT INTO Customer (ID,Name,Subject, OrderDate) VALUES ('$ID', '$name', '$status', '$ODate')");
mysql_query("INSERT INTO Order (ID,Subject, Department, Status, OrderDate, Receive, Notes) VALUES ('$ID', '$status', 'Financial', 'Financial Department', '$ODate', 'NO', 'Notes')");
?>

It just works with the first table and does not work with the second table.

Can some one help solving this problem?

Thanks

You need to check for errors:

<?php
$query1 = "INSERT INTO Customer (ID,Name,Subject, OrderDate) VALUES ('$ID', '$name', '$status', '$ODate')";
if(!mysql_query($query1)) {
  throw new Exception(mysql_error());
}

$query2 = "INSERT INTO Order (ID,Subject, Department, Status, OrderDate, Receive, Notes) VALUES ('$ID', '$status', 'Financial', 'Financial Department', '$ODate', 'NO', 'Notes')";
if(!mysql_query($query2)) {
  throw new Exception(mysql_error());
}

I'm guessing you are getting an error because Order is a reserved word in MySQL and should be escaped accordingly:

$query2 = "INSERT INTO `Order` (ID,Subject, Department, Status, OrderDate, Receive, Notes) VALUES ('$ID', '$status', 'Financial', 'Financial Department', '$ODate', 'NO', 'Notes')";

It also seems to me like you're inserting a fixed value as a primary key - are you sure that's what you want?


As I said in the comments, you should stop using mysql_ functions completely and use MySQLi or PDO instead.

First of all thanks to DCoder who helped me to solve the problem and advised me to use PDO and MySQLi.

The problem was with the tabel name Order, when I replaced it with a new name, it works fine.

I thought the problem with using two mysql_query but it is not. The table name that I used is a reserved word in MySQL.

Thanks