มานทำเป็น array ไม่ได่มีวิธีอื่นมะ <?php INSERT INTO T5_ADVISOR_LIST window.opener.location.reload(); window.close(this);
Code (PHP)
<?php
INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES (122,161),(122,163),(122,165),(122,123),(122,361),(122,362)
Warning: oci_execute() [function.oci-execute]: ORA-00933: สิ้นสุดคำสั่ง SQL ไม่ถูกต้อง in D:\InetPub\D4LP_V20\admin\addStu4Advisor.php on line 70
?>
Code (PHP)2
<?php
if (isset($Save)) {
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
for ($K=0;$K<count($myArrayList);$K++) {
if ($sql2=="") $sql2.="($AdvisorID,$myArrayList[$K])";
else $sql2.=",($AdvisorID,$myArrayList[$K])";
}
echo $sql.=$sql2;
}
$doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
?>
Tag : - - - -
Date :
2009-04-24 15:54:14
By :
evening
View :
1899
Reply :
15
Code (PHP)
<?php
$StuID2Save = "โคตรอาไรกันนี้ , มั่วๆๆๆไปได้มิ";
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
for ($K=0;$K<count($myArrayList);$K++) {
if ($sql2=="") $sql2.="('$myArrayList[$K]'";
else $sql2.=",'$myArrayList[$K]')";
}
echo $sql.=$sql2;
echo "<br>";
echo $AdvisorID;
//$result = mysql_query($sql);
}
exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
?>
มันเป็นอะไรครับ ผมว่ามันก็ได้นะ
Date :
2009-04-24 16:38:26
By :
teez1232002
ความต้องการเป็นแบบไหนครับ
Date :
2009-04-24 16:39:32
By :
teez1232002
คือ อันที่จริง ตาม Code (PHP)2 หละครับคือตัวเก็บ
แต่พอ ใส่ข้อมูลพร้อมๆกันที่เดียวแบบ โค้ตแรก กลับไม่ได้
Insert พร้อมๆกัน แบบ multivalue อะครับ
Code
INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES (122,161),(122,163),(122,165),(122,123),(122,361),(122,362)
Date :
2009-04-24 16:50:44
By :
evening
คือปัญหาคือ พอ ใส่ พร้อมๆกัน กลับไม่ได้
งง
Date :
2009-04-24 16:52:41
By :
evening
ออ เข้าใจแหละ
ต้องเอา คำสั่ง insert ไปวนรับ ด้วยครับแต่ละค่าลองดูนะ
Code (PHP)
<?php
$StuID2Save = "222 , 223 , 224 , 225";
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
for ($K=0;$K<count($myArrayList);$K++) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
if ($sql2=="") $sql2.="(122,$myArrayList[$K])";
else $sql2.=",(122,$myArrayList[$K])";
echo $sql.=$sql2."<br><br>";
}
}
/* $doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
*/ exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
?>
ปัญหามาปัญญาเกิด ตอบผิดเค้าจะว่าเรามั้ยหว่า
Date :
2009-04-24 17:12:17
By :
teez1232002
บ่ได้คือเก่า
วิธีนี้ผมลอกแล้วครับ
ยังติดปัญหาเหมือนเดิม
Date :
2009-04-24 17:43:09
By :
evening
สงสัยอาจเป็น เพราะ syntax ไม่ตรงกับตัว oracle หละมั้ง เดวขอดู manaul ก่อน
Date :
2009-04-24 17:45:45
By :
evening
ลอบแบบนี้สิครับ
Code (PHP)
<?php
if (isset($Save)) {
$myArrayList = explode(",",trim($StuID2Save));
if (count($myArrayList) >= 1) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
for ($K = 0; $K <= count($myArrayList); $K++) {
if ($sql2 == "") {
$sql2.="($AdvisorID,$myArrayList['$K'])";
}else{
$sql2.=",($AdvisorID,$myArrayList['$K'])";
echo $sql.=$sql2;
}
}
}
}
$doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
?>
ลองดูนะครับ ผิดถูกอย่าว่ากันนะครับ
Date :
2009-04-24 20:16:57
By :
mosaddzero
เหนื่อยใจ
Date :
2009-04-25 12:01:39
By :
evening
งันขอดูโคดแบบเต็ม ๆ หน่อยสิครับ
เพือจาช่วยได้
Date :
2009-04-25 12:15:05
By :
mosaddzero
Code (PHP)
<?php
<? include_once ("../common/config.php");
session_start(); $path="../";
if (session_is_registered("Logedin") and $Logedin==true and !session_is_registered("UserID")
and session_is_registered("ClientID") and $ClientID>0) header("Location: ../portfolio");
if ($UserType==1) header("Location: ../");
?>
<Html>
<Head>
<? include_once("../common/header.inc"); ?>
<script src="../js/popup.js" type="text/javascript"></script>
<Script language="JavaScript">
function doSubmitForm(frm)
{
var stuid_all='';
for (i=0; i < frm.elements.length; i++){
var el = frm.elements[i];
if ((el.name.indexOf('Stu_')==0) && el.checked &&(el.type=='checkbox')) {
if (stuid_all!='') stuid_all+=','+el.value; else stuid_all=el.value;
}
}
if (stuid_all=="") stuid_all=0;
frm.StuID2Save.value=stuid_all;
return (stuid_all==0) ? false : true;
}
function CA(isO,noHL){
for (var i=0;i<frm.elements.length;i++)
{
var e=frm.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox'))
{
if (isO != 1) e.checked=frm.allbox.checked;
else e.tabIndex=i;
}
}
}
function CCA(CB,noHL){
var TB=TO=0;
for (var i=0;i<frm.elements.length;i++) {
var e=frm.elements[i];
if ((e.name != 'allbox') && (e.type=='checkbox')) {
TB++;
if (e.checked) TO++;
}
}
frm.allbox.checked=(TO==TB)?true:false;
}
</SCRIPT>
</Head>
<Body onLoad="self.focus();" style="padding:10px;">
<?
include_once("../common/function.php");
if ((!session_is_registered("Logedin")) or (!$Logedin)) {include_once("../member/login.php"); exit; }
include_once( "../common/db_variable.php");
if (!isset($AdvisorID)) exit;
if (isset($Save)) {
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
for ($K=0;$K<count($myArrayList);$K++) {
if ($sql2=="") $sql2.="($AdvisorID,$myArrayList[$K])";
else $sql2.=",($AdvisorID,$myArrayList[$K])";
}
echo $sql.=$sql2;
}
$doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
}
$fofecth=oci_parse($dblink,"SELECT * FROM T5_MEMBER WHERE USERID='$AdvisorID'");oci_execute($fofecth);
$getAdvisor=oci_fetch_array($fofecth);
?>
<FORM action="<?echo $SCRIPT_NAME; ?>" method="get" name="FormStu2">
<Script language="JavaScript">var frm2=document.FormStu2;</SCRIPT>
<INPUT type="hidden" name="AdvisorID" value="<? echo $AdvisorID;?>">
<INPUT type="hidden" name="OFacID" value="<? echo $FacID;?>">
<TABLE border="0" cellpadding="0" cellspacing="0" width="100%">
<TR>
<TD>
<Table cellpadding="1" cellspacing="0">
<Tr>
<Td class="bgcolor2" style="line-Height:18px;padding-left:20px;padding-right:20px;">
<?if ($Lang=="TH") echo "???????????????"; else echo "Student list";?>
</Td>
</Tr>
</Table>
</TD>
</TR>
</TABLE>
<Table cellspacing="0" cellpadding="1" border="0" align="center" class="BOX2" width="100%">
<Tr bgcolor="#FFEEE6">
<Td colspan="5" style="padding-left:30px;padding-top:5px; padding-bottom:5px;">
<?
$facQue=oci_parse($dblink,"SELECT * FROM T5_FACULTY ORDER BY FACID");oci_execute($facQue);
echo ($Lang=="TH") ? "???" : "Faculty";
echo "<Select name=\"FacID\" onchange=\"frm2.submit();\">";
echo "<Option value=0>[-- Please select Faculty --]";
while ($getFac=oci_fetch_array($facQue)) {
if (!isset($FacID)) $FacID=$getFac["FACID"];
echo "<Option value=\"$getFac[FACID]\" ";
if ($getFac["FACID"]==$FacID) echo "selected"; echo ">";
echo ($Lang=="TH" and $getFac["FACNAMET"]<>"") ? $getFac["FACNAMET"] : $getFac["FACNAMEE"];
echo "\n";
}
echo "</Select><br>\n";
if ($FacID<>$OFacID and $OFacID<>"") $DeptID=0;
$deptQue=oci_parse($dblink,"SELECT * FROM T5_DEPARTMENT WHERE FACID='$FacID' ORDER BY DEPTID");oci_execute($deptQue);
echo ($Lang=="TH") ? "???????/????????" : "Department/Program";
echo "<Select name=\"DeptID\" onchange=\"frm2.submit();\">";
echo "<Option value=0>[-- Please select Program --]";
while ($getDept=oci_fetch_array($deptQue)) {
if (!isset($DeptID)) $DeptID=$getDept["DEPTID"];
echo "<Option value=\"$getDept[DEPTID]\" ";
if ($getDept["DEPTID"]==$DeptID) echo "selected"; echo ">";
echo ($Lang=="TH" and $getDept["DEPTNAMET"]<>"") ? $getDept["DEPTNAMET"] : $getDept["DEPTNAMEE"];
echo "\n";
}
echo "</Select><br>\n";
?>
</Td>
</Tr>
</Form>
<FORM action="<?echo $SCRIPT_NAME; ?>" method="post" onSubmit="return doSubmitForm(this);" name="FormStu">
<Script language="JavaScript">var frm=document.FormStu;</SCRIPT>
<INPUT type="hidden" name="AdvisorID" value="<? echo $AdvisorID;?>">
<INPUT type="hidden" name="StuID2Save" value="">
<Tr bgcolor="#FFEEE6">
<Td class="box3b box2t" align="center" width="10"><Input type="Checkbox" name="allbox" onClick="CA()" title="Select or de-select all students" ></Td>
<Td class="box3b box2r box2t" align="center" width="25">No</Td>
<Td class="box3b box2r box2t" width="90">Student Code</Td>
<Td class="box3b box2r box2t">Student name</Td>
<Td class="box3b box2t">Major</Td>
</Tr>
<?
$sql="SELECT * FROM V_T5_MEMBER
WHERE USERTYPE=1 ";
$sql.="AND FACID='$FacID' ";
if ($DeptID>0) $sql.="AND DEPTID='$DeptID' ";
$sql.="AND USERID NOT IN (SELECT STUID USERID FROM T5_ADVISOR_LIST WHERE ADVISORID='$AdvisorID')
ORDER BY USERLOGIN";
$stuQue=oci_parse($dblink,$sql);oci_execute($stuQue);
$sqls="SELECT COUNT(*) GETROWS FROM V_T5_MEMBER WHERE USERTYPE=1 AND FACID='$FacID' ";
if ($DeptID>0) $sql.="AND DEPTID='$DeptID' ";
$sqls.="AND USERID NOT IN (SELECT STUID USERID FROM T5_ADVISOR_LIST WHERE ADVISORID='$AdvisorID')
ORDER BY USERLOGIN";
$stuQues=oci_parse($dblink,$sqls);oci_execute($stuQues);
$getStus=oci_fetch_array($stuQues);
$maxStu=$getStus['GETROWS'];
if ($maxStu<=0) echo "<tr><td height=100 colspan=4 align=\"center\" class=\"text0\">Their is no student in this program.</td></tr>\n";
while ($getStu=oci_fetch_array($stuQue)){ $N++;
echo $getStu["USERPNAMET"];
echo "<Tr>";
echo "<Td align=\"center\" class=\"box3b\"><Input type=\"Checkbox\" name=\"Stu_$getStu[USERID]\" value=\"$getStu[USERID]\" onClick=\"CCA(this)\"></Td>";
echo "<Td align=\"center\" class=\"box3br\" nowrap>$N</Td>";
echo "<Td align=\"center\" class=\"box3br\">$getStu[USERLOGIN]</Td>";
echo "<Td class=\"box3br\">";
if ($Lang=="TH") echo ($getStu["USERNAMET"]<>"") ? "$getStu[USERNAMET] $getStu[USERSNAMET]" : "$getStu[USERPNAME] $getStu[USERSNAME]";
else echo ($getStu['USERNAME']<>"") ? "$getStu[USERNAME] $getStu[USERSNAME]" : "$getStu[USERNAMET] $getStu[USERSNAMET]";
echo "</Td>";
echo "<Td class=\"box3b smf\">"; echo ($Lang=="TH" and $getStu["DEPTNAMET"]<>"") ? "$getStu[DEPTNAMET]" : "$getStu[DEPTNAMEE]"; echo "</Td>";
echo "</Tr>\n";
}
?>
</Table>
<div align="right" style="padding-top:5px;">
<Input type="Submit" value="<?echo ($Lang=="TH") ? " ?????? " : "Update";?>" name="Save" class="button">
<Input type="Button" onClick="window.close(this)" value="<?if ($Lang=="TH") echo " ?????? "; else echo "Cancel";?>" class="button">
</div>
</FORM>
</Body>
</Html>
?>
Date :
2009-04-26 11:29:23
By :
evening
Error starting at line 1 in command:
INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES (1,165),(1,362)
Error at Command Line:1 Column:60
Error report:
SQL Error: ORA-00933: สิ้นสุดคำสั่ง SQL ไม่ถูกต้อง
00933. 00000 - "SQL command not properly ended"
*Cause:
*Action:
Date :
2009-04-26 11:32:38
By :
evening
แล้วครับ
เดิม
Code (PHP)
<?php
if (isset($Save)) {
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
for ($K=0;$K<count($myArrayList);$K++) {
if ($sql2=="") $sql2.="($AdvisorID,$myArrayList[$K])";
else $sql2.=",($AdvisorID,$myArrayList[$K])";
}
echo $sql.=$sql2;
}
$doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
exit;
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
//exit;
?>
แก้เป็น
Code (PHP)
<?php
if (isset($Save)) {
//$myArrayList=explode(",",trim($Save));
$myArrayList=explode(",",trim($StuID2Save));
if (count($myArrayList)>0) {
for ($K=0;$K<count($myArrayList);$K++) {
$sql="INSERT INTO T5_ADVISOR_LIST (ADVISORID,STUID) VALUES ";
$sql2="";
$sql2.=($sql2==NULL)?"($AdvisorID,$myArrayList[$K])":"";
$sql.=$sql2;
$doInsert=oci_parse($dblink,$sql);
oci_execute($doInsert);
}
}
echo "<Script language=\"JavaScript\">window.opener.location.reload(); window.close(this);</SCRIPT>";
exit;
}
?>
Date :
2009-04-26 12:05:10
By :
evening
<?
$host= "localhost";
$userdb = "root";
$password = "1234";
$dbname = "test1";
mysql_connect($host,$userdb,$password);
$sql = " INSERT INTO user ";
$sql .= " (FName,LName,Birthday) ";
$sql .= " VALUES ";
$sql .= " ('$FName','$LName','$Birthday') ";
$result = mysql_db_query($dbname,$sql);
if($result == 1) {
echo "INSERT OK ";
} else {
echo "CANNOT INSERT ";
}
?>
อยากรู้ว่าผิดตรงไหนคะแล้วตอนแรกINSERT OK พอดีมือซนคลิ้กไปสองทีกลายเป็นcannot insert แก้ไม่ได้คะช่วยแก้ให้หน่อยนะคะ ทำไม่ได้เพราะไม่มีความรู้เรื่องนี้เลยแต่อยากเรียนมากๆค่ะ
Date :
2009-09-03 18:49:26
By :
Pretty Au
Load balance : Server 03