|
|
|
ดึง id ของอีกตารางมาใช้ยังไงค่ะช่วยหนูที หนูใช้โปรแกรม dreamweaver |
|
|
|
|
|
|
|
เมื่อล็อกอินหน้าเข้ามา หน้ากรอกข้อมูล แล้วกดบันทึกมันขึ้น
Code
Cannot add or update a child row: a foreign key constraint fails (`restaurant`.`restaurant_details`, CONSTRAINT `restaurant_details_ibfk_1` FOREIGN KEY (`own_id`) REFERENCES `ownerr` (`own_id`))
หนูจะทำยังไงให้ มันดึง id จาก ตารางที่ล็อกอินเข้ามาได้ค่ะ
ช่วยหนูทีค่ะหนูพึ่งหัดทำหนูใช้ดรีมทำ
อันนี้เป็นโค้ดอ๊ะค่ะ
Code (PHP)
<?php
//initialize the session
if (!isset($_SESSION)) {
session_start();
}
// ** Logout the current user. **
$logoutAction = $_SERVER['PHP_SELF']."?doLogout=true";
if ((isset($_SERVER['QUERY_STRING'])) && ($_SERVER['QUERY_STRING'] != "")){
$logoutAction .="&". htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_GET['doLogout'])) &&($_GET['doLogout']=="true")){
//to fully log out a visitor we need to clear the session varialbles
$_SESSION['MM_Username'] = NULL;
$_SESSION['MM_UserGroup'] = NULL;
$_SESSION['PrevUrl'] = NULL;
unset($_SESSION['MM_Username']);
unset($_SESSION['MM_UserGroup']);
unset($_SESSION['PrevUrl']);
$logoutGoTo = "1login.php";
if ($logoutGoTo) {
header("Location: $logoutGoTo");
exit;
}
}
?>
<?php
if (!isset($_SESSION)) {
session_start();
}
$MM_authorizedUsers = "";
$MM_donotCheckaccess = "true";
// *** Restrict Access To Page: Grant or deny access to this page
function isAuthorized($strUsers, $strGroups, $UserName, $UserGroup) {
// For security, start by assuming the visitor is NOT authorized.
$isValid = False;
// When a visitor has logged into this site, the Session variable MM_Username set equal to their username.
// Therefore, we know that a user is NOT logged in if that Session variable is blank.
if (!empty($UserName)) {
// Besides being logged in, you may restrict access to only certain users based on an ID established when they login.
// Parse the strings into arrays.
$arrUsers = Explode(",", $strUsers);
$arrGroups = Explode(",", $strGroups);
if (in_array($UserName, $arrUsers)) {
$isValid = true;
}
// Or, you may restrict access to only certain users based on their username.
if (in_array($UserGroup, $arrGroups)) {
$isValid = true;
}
if (($strUsers == "") && true) {
$isValid = true;
}
}
return $isValid;
}
$MM_restrictGoTo = "1login.php";
if (!((isset($_SESSION['MM_Username'])) && (isAuthorized("",$MM_authorizedUsers, $_SESSION['MM_Username'], $_SESSION['MM_UserGroup'])))) {
$MM_qsChar = "?";
$MM_referrer = $_SERVER['PHP_SELF'];
if (strpos($MM_restrictGoTo, "?")) $MM_qsChar = "&";
if (isset($_SERVER['QUERY_STRING']) && strlen($_SERVER['QUERY_STRING']) > 0)
$MM_referrer .= "?" . $_SERVER['QUERY_STRING'];
$MM_restrictGoTo = $MM_restrictGoTo. $MM_qsChar . "accesscheck=" . urlencode($MM_referrer);
header("Location: ". $MM_restrictGoTo);
exit;
}
?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO restaurant_details (res_four_name, res_name, res_address, res_description, res_phon, res_price_strat, res_price_end, pro_promotion, pro_percent, pro_description, dateStart, dateEnd, lat, lng, res_picture) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['res_four_name'], "int"),
GetSQLValueString($_POST['res_name'], "text"),
GetSQLValueString($_POST['res_address'], "text"),
GetSQLValueString($_POST['res_description'], "text"),
GetSQLValueString($_POST['res_phon'], "text"),
GetSQLValueString($_POST['res_price_strat'], "int"),
GetSQLValueString($_POST['res_price_end'], "int"),
GetSQLValueString($_POST['pro_promotion'], "int"),
GetSQLValueString($_POST['pro_percent'], "int"),
GetSQLValueString($_POST['pro_description'], "text"),
GetSQLValueString($_POST['dateStart'], "date"),
GetSQLValueString($_POST['dateEnd'], "date"),
GetSQLValueString($_POST['lat'], "text"),
GetSQLValueString($_POST['lng'], "text"),
GetSQLValueString(dwUpload($_FILES['res_picture']), "text"));
mysql_select_db($database_restaurant, $restaurant);
$Result1 = mysql_query($insertSQL, $restaurant) or die(mysql_error());
$updateGoTo = "4view.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
$colname_indexx = "-1";
if (isset($_GET['uu_user'])) {
$colname_indexx = $_GET['uu_user'];
}
mysql_select_db($database_restaurant, $restaurant);
$query_indexx = sprintf("SELECT * FROM restaurant_details WHERE own_id = %s", GetSQLValueString($colname_indexx, "int"));
$indexx = mysql_query($query_indexx, $restaurant) or die(mysql_error());
$row_indexx = mysql_fetch_assoc($indexx);
?>
Tag : PHP, MySQL, JavaScript
|
ประวัติการแก้ไข 2016-08-28 12:26:56 2016-08-28 16:22:54
|
|
|
|
|
Date :
2016-08-28 00:40:22 |
By :
Yauwared25 |
View :
902 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
คุณใช้การเชื่อม FK แต่ข้อมูลที่เป็น PK ที่อ้างถึงจากอีก Table ไม่มีครับ
|
|
|
|
|
Date :
2016-08-29 10:45:03 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุนนะคะหนูทำได้แล้ว
Code (PHP)
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form")) {
$insertSQL = sprintf("INSERT INTO restaurant_details (res_four_name, res_type_name, res_name, res_address, res_description, res_phon, res_price_strat, res_price_end, pro_promotion, pro_percent, pro_description, dateStart, dateEnd, lat, lng, res_picture, own_id) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['res_four_name'], "int"),
GetSQLValueString($_POST['res_type_name'], "int"),
GetSQLValueString($_POST['res_name'], "text"),
GetSQLValueString($_POST['res_address'], "text"),
GetSQLValueString($_POST['res_description'], "text"),
GetSQLValueString($_POST['res_phon'], "text"),
GetSQLValueString($_POST['res_price_strat'], "int"),
GetSQLValueString($_POST['res_price_end'], "int"),
GetSQLValueString($_POST['pro_promotion'], "int"),
GetSQLValueString($_POST['pro_percent'], "int"),
GetSQLValueString($_POST['pro_description'], "text"),
GetSQLValueString($_POST['dateStart'], "date"),
GetSQLValueString($_POST['dateEnd'], "date"),
GetSQLValueString($_POST['lat'], "text"),
GetSQLValueString($_POST['lng'], "text"),
GetSQLValueString(dwUpload($_FILES['res_picture']), "text"),
GetSQLValueString($_POST['owner'], "text")
);
mysql_select_db($database_restaurant, $restaurant);
$Result1 = mysql_query($insertSQL, $restaurant) or die(mysql_error());
$updateGoTo = "3form.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}
|
|
|
|
|
Date :
2016-09-03 02:54:35 |
By :
Yauwared25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 00
|