|
|
|
ถามเกี่ยวกับ Multi iframe submit ว่าผมจะต่อกับ DB ยังไงครับ |
|
|
|
|
|
|
|
ช่วยอธิบายโค๊ดพวกนี้หน่อยครับ ถ้าผมจะนำมา Connect กับ DB MySQL ว่าผมต้องเปลี่ยนตรงไหนอะไรยังไงบ้างครับ ขอบคุณครับCode (PHP)
<?php
//ajax action
$action = empty($_GET['action']) ? '' : $_GET['action'];
$name = empty($_POST['name']) ? '' : escape($_POST['name']);
$detail = empty($_POST['detail']) ? '' : escape($_POST['detail']);
$table = empty($_GET['table']) ? '' : str_replace('`','',escape($_GET['table']));
switch($action):
case 'form':
?>
<?php echo $table;?>:
<form id="f-<?php echo $table;?>" method="post" action="?action=add&table=<?php echo $table;?>" style="border:solid blue 1px;margin-top:10px;">
name:<input type="text" name="name" value="name1" /><br />
detail:<input type="text" name="detail" value="detail1" /><br />
</form>
<?php
exit;
break;
case 'add':
echo "INSERT INTO `$table`(name,detail) VALUES('$name','$detail')";
exit;
break;
endswitch;
function escape($s){ return $s; /*should be mysql_real_escape_string($s);*/}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="ltr" lang="th" xml:lang="th">
<head>
<title>untitle</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript">
//<![CDATA[
$(function(){
$('#execute-button').click(function(e){
e.preventDefault();
var forms = ['f-tb1','f-tb2','f-tb3'];
var frames = ['f1','f2','f3'];
var fs = [];
for(var i=0; i<forms.length; i++){
fs.push($('#'+forms[i],window[frames[i]].document));
}
$(fs).each(function(){
$.ajax({
url: $(this).attr('action'),
dataType: 'html',
type: 'post',
data: $(this).serialize(),
success: function(data){
$('#process').append('<br/>'+data);
}
});
});
});
});
//]]>
</script>
</head>
<body>
<iframe name="f1" src="?action=form&table=tb1" width="300" height="125"></iframe>
<iframe name="f2" src="?action=form&table=tb2" width="300" height="125"></iframe>
<iframe name="f3" src="?action=form&table=tb3" width="300" height="125"></iframe>
<div id="process"></div>
<button id="execute-button">execute</button>
</body>
</html>
Tag : PHP, MySQL, Ajax
|
|
|
|
|
|
Date :
2014-04-26 02:26:45 |
By :
Harizadoz |
View :
693 |
Reply :
4 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ทำได้หละครับ
|
|
|
|
|
Date :
2014-04-26 03:00:32 |
By :
Harizadoz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ผมเปลี่ยนตรง Code (PHP)
echo "INSERT INTO `$table`(name,detail) VALUES('$name','$detail')";
เป็น
Code (PHP)
$objConnect = mysql_connect("localhost","root","12345") or die("Error Connect to Database");
$objDB = mysql_select_db("education");
@mysql_query("SET NAMES UTF8");
$strSQL ="insert into vocation" ;
$strSQL .="(id_subject,name,credit_vocation) ";
$strSQL .="VALUES ";
$strSQL .="('".$_POST["idv"]."','".$_POST["subv"]."', ";
$strSQL .="'".$_POST["creditv"]."') ";
$objQuery = mysql_query($strSQL);
แค่นี้เองครับ มันก้เซฟลง DB ให้เลย
|
|
|
|
|
Date :
2014-04-26 11:26:03 |
By :
Harizadoz |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Date :
2014-04-26 11:44:11 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 03
|