Problem with PHP of MySQL
Posted: Wed Sep 11, 2002 11:59 am
Hi,
I've a problem with PHP or MySQL, so don't kill me if I'm cross posting !
Description of the problem:
a) In file 1 i've got a form. The variables are nicely posted to file 2, no problem.
b) In file 2 I want to perform the following things:
1) inserting the posted variables into an existing table
2) after this "insert query" performing a second insert query passing values from another table into the same table where the posted variables were inserted.
I used the following code to perfom the first "insert query":
This works fine. But when I insert the second "insert query" (after the fist)
it no longer performs any of them.
I used following code:
Strangely, when I de-activated the first "insert query" the second inserts a new record with the value "street" into to the table.
But it can never be correct data entry, because the address_finance-tabel doesn't contain an acco_id yet.
Would appreciate some help to solve this.
Thanks in advance,
Gijs
I've a problem with PHP or MySQL, so don't kill me if I'm cross posting !
Description of the problem:
a) In file 1 i've got a form. The variables are nicely posted to file 2, no problem.
b) In file 2 I want to perform the following things:
1) inserting the posted variables into an existing table
2) after this "insert query" performing a second insert query passing values from another table into the same table where the posted variables were inserted.
I used the following code to perfom the first "insert query":
Code: Select all
if (isset($_POSTї'action'])) {
switch ($_POSTї'action']) {
case 'insert':
// Check if all the variables are set
if (isset($_POSTї'acco_id']) && isset($_POSTї'acco_name']) && isset($_POSTї'city_zip']) && isset($_POSTї'city_name'])) {
// Inserting the data posted from the form
$address_insert_SQL = "INSERT INTO acco_address_finance (acco_id, company, zip, city)
VALUES('".$_POSTї'acco_id']."', '".$_POSTї'acco_name']."', '".$_POSTї'city_zip']."', '".$_POSTї'city_name']."')";
// Displaying a message depending on the outcome of the query
$bool = mysql_query($address_insert_SQL);
if($bool == 1) echo "<SCRIPT LANGUAGE=Javascript>window.alert('The Hotel Address has been copied to the Financial Address.')</script>";
if($bool <> 1) echo "<SCRIPT LANGUAGE=Javascript>window.alert('There has been an error.')</script>";
// displaying error message if variables are not set
} else {
echo "ERROR the variables form the form Copy Hotel Address are not set !";
}
// Kicking out the variable
unset($_POSTї'action']);
// Stopping the switch statement
break;
default :
echo "The default value for the switch statement";
}
} else {
// actions when $_POSTї'action'] not set
// not defined yet
}
?>it no longer performs any of them.
I used following code:
Code: Select all
// Inserting the data from address to address_finance
$address_copy_SQL = "INSERT INTO acco_address_finance (street)
SELECT acco_address.street FROM acco_address
WHERE acco_address.acco_id='".$_POSTї'acco_id']."'";But it can never be correct data entry, because the address_finance-tabel doesn't contain an acco_id yet.
Would appreciate some help to solve this.
Thanks in advance,
Gijs