Hi Everyone,
I want to write a query to insert into carsafety(table#2) where carID=CarID in the cars table and cars.studentID= the studentID selected in the page. ($CustomerID2Update)
i tested this query in mySQL and it works fine, but it doesn't update from my php page.
Thanks for your help.
table cars (carID , studentID, ...)
table carsafty(carID, safetyID)
<?php
$a = session_id();
if(empty($a)) session_start();
$_SESSION['CustomerID2Update'] = 0 ;
if ($_SESSION['CustomerID']==0) {
$_SESSION['Message'] = "Insert Preferences: Permission Denied";
header("Location: index.php") ;
} else {
include "MySQLConnector.txt";
}
$CustomerID2Update = $_REQUEST['CustomerID2Update'];
$query = "DELETE FROM carsafety WHERE cars.CarID = carsafety.CarID AND cars.CustomerID = " . $CustomerID2Update ;
if(!empty($_REQUEST['chkSaf1'])) {
$SafGroup1 = trim($_REQUEST['chkSaf1']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup1 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf2'])) {
$SafGroup2 = trim($_REQUEST['chkSaf2']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup2 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf3'])) {
$SafGroup3 = trim($_REQUEST['chkSaf3']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup3 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf4'])) {
$SafGroup4 = trim($_REQUEST['chkSaf4']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup4 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf5'])) {
$SafGroup5 = trim($_REQUEST['chkSaf5']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup5 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf6'])) {
$SafGroup6 = trim($_REQUEST['chkSaf6']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup6 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf7'])) {
$SafGroup7 = trim($_REQUEST['chkSaf7']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup7 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
if(!empty($_REQUEST['chkSaf8'])) {
$SafGroup8 = trim($_REQUEST['chkSaf8']);
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup8 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}