Jump to content

Recommended Posts

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";

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/142637-insert-function-isnt-working/
Share on other sites

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?

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";

}

?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.