插入查询-php,MySQL [英] insert query -php, MySQL

查看:77
本文介绍了插入查询-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();


这篇关于插入查询-php,MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆