插入查询-php,MySQL
问题描述:
大家好,
我想编写一个查询以插入到carsafety(table#2)中,其中carID = cars表中的carID和cars.studentID =在页面中选择的studentID. ($ CustomerID2Update)
我在mySQL中测试了此查询,它工作正常,但不会从我的php页面更新.
感谢您的帮助.
桌车(carID,studentID等)
表carafty(carID,safetyID)
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) { // Not logged in
$_SESSION['Message'] = "Insert Preferences: Permission Denied";
header("Location: index.php") ;
} else {
include "MySQLConnector.txt";
}
// Get the data from the form:
$CustomerID2Update = $_REQUEST['CustomerID2Update']; // Hidden Field
$query = "DELETE FROM carsafety WHERE cars.CarID = carsafety.CarID AND cars.CustomerID = " . $CustomerID2Update ;
if(!empty($_REQUEST['chkSaf1'])) {
$SafGroup1 = trim($_REQUEST['chkSaf1']); // Constituency Group 1
$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']); // Constituency Group 2
$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']); // Constituency Group 3
$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']); // Constituency Group 4
$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']); // Constituency Group 5
$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']); // Constituency Group 6
$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']); // Constituency Group 7
$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']); // Constituency Group 7
$query = "INSERT INTO carsafety CarID, SafetyID SELECT CarID, '" . $SafGroup8 . "'
from cars WHERE cars.CustomerID= " . $CustomerID2Update. " ";
mysqli_query($dbc,$query);
}
答
CustomerID2Update)
我在mySQL中测试了此查询,它工作正常,但不会从我的php页面更新.
感谢您的帮助.
桌车(carID,studentID等)
表carafty(carID,safetyID)
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_id(); if(empty(
a))session_start();
a)) session_start();