hewstone999 Posted January 27, 2009 Share Posted January 27, 2009 I have some code(below) that the INSERT function wont work. The error message displayed is: "Fatal error</b>: Uncaught exception 'com_exception' with message 'Error [0x8002000e] Invalid number of parameters." Code: <? if ($a == 1) { echo "<script type='text/javascript'> \n"; echo "var temp1; \n"; echo "total; \n"; echo "var total = 0; \n"; echo "var x = 0; \n"; echo "for (counter=0;counter<3;counter++){ \n"; echo "x = x + 1; \n"; echo "var temp3 = 'colid' + x; \n"; echo "var content=document.getElementsByTagName(temp3) \n"; echo "temp1 = content[0]; \n"; echo "for(c=0;c<content.length;c++) { \n"; echo "var temp4 = 1; \n"; echo "for(d=0;d<content.length;d++){ \n"; echo "if (c == d) {} \n"; echo "else{ \n"; echo "if (content[d].innerHTML == content[c].innerHTML) { \n"; echo "total = total + 1; \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "$rS2 = $db_conn->execute(\"INSERT INTO TempData(Col1) VALUES('total')\");\n"; echo "</script>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/ Share on other sites More sharing options...
MadTechie Posted January 27, 2009 Share Posted January 27, 2009 Erm.. echo "$rS2 = $db_conn->execute(\"INSERT INTO TempData(Col1) VALUES('total')\");\n"; i assume you mean $rS2 = $db_conn->execute("INSERT INTO TempData(Col1) VALUES('total')"); but i don't see where your setting $db_conn Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/#findComment-747604 Share on other sites More sharing options...
kenrbnsn Posted January 27, 2009 Share Posted January 27, 2009 It looks like you are trying to mix Javascript and PHP. Your code doesn't make any sense, please explain what you are trying to do. Ken Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/#findComment-747607 Share on other sites More sharing options...
haku Posted January 27, 2009 Share Posted January 27, 2009 Ken is spot on. You are echoing php code to the browser with your javascript. Not gonna work. Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/#findComment-747645 Share on other sites More sharing options...
hewstone999 Posted January 27, 2009 Author Share Posted January 27, 2009 This is the code that connects to the Database $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./Database1.mdb").";"; $db_conn->open($connstr); I have a html table and i want to insert the value of the table into the access database but cant INSERT the sql statement using php with Javascript. any ideas on how i can do this? Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/#findComment-747865 Share on other sites More sharing options...
MadTechie Posted January 27, 2009 Share Posted January 27, 2009 Your Options are 1. Form + POST|GET 2. Javascript (See AJAX) Try this.. (not really planned it out but will atleast give you an idea bout AJAX) <?php if(!empty($_GET['Total'])) { $Total = (float)$_GET['Total']; $db_conn = new COM("ADODB.Connection"); $connstr = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=". realpath("./Database1.mdb").";"; $db_conn->open($connstr); $rS2 = $db_conn->execute("INSERT INTO TempData(Col1) VALUES('$Total')"); exit(); } ?> function ajaxFunction(ID, Total) { var xmlHttp; try { // Firefox, Opera 8.0+, Safari xmlHttp=new XMLHttpRequest(); }catch(e){ // Internet Explorer try { xmlHttp=new ActiveXObject("Msxml2.XMLHTTP"); }catch(e){ try { xmlHttp=new ActiveXObject("Microsoft.XMLHTTP"); }catch(e){ alert("Your browser does not support AJAX!"); return false; } } } xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { document.getElementById(ID).innerHTML = xmlHttp.responseText; } } xmlHttp.open("GET", "?Total="+Total,true); xmlHttp.send(null); } <?php if ($a == 1) { echo "<script type='text/javascript'> \n"; echo "var temp1; \n"; echo "total; \n"; echo "var total = 0; \n"; echo "var x = 0; \n"; echo "for (counter=0;counter<3;counter++){ \n"; echo "x = x + 1; \n"; echo "var temp3 = 'colid' + x; \n"; echo "var content=document.getElementsByTagName(temp3) \n"; echo "temp1 = content[0]; \n"; echo "for(c=0;c<content.length;c++) { \n"; echo "var temp4 = 1; \n"; echo "for(d=0;d<content.length;d++){ \n"; echo "if (c == d) {} \n"; echo "else{ \n"; echo "if (content[d].innerHTML == content[c].innerHTML) { \n"; echo "total = total + 1; \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "} \n"; echo "ajaxFunction('result', Total);\n"; echo "</script>\n"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/#findComment-747870 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.