I am trying to submit entries in a form to a database. I am using
[code[
action="$_SERVE R[PHP_SELF]"
[/code]
within my submission form and
I am getting the connection to the database but I my script is not executing, probably due to a syntax error which I can't see.
here is the code, first the submission page, then the php script
submission page
php script
Using alerts to debug I am getting OK,1, 2, 3, 4, 200, "blank alert".
rpjd
[code[
action="$_SERVE R[PHP_SELF]"
[/code]
within my submission form and
Code:
$_POST['value-to-be-submitted']
here is the code, first the submission page, then the php script
submission page
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<? include("http://localhost/Project/customers.php") ?>
<HTML>
<HEAD>
<TITLE> ALLIED AUTO PARTS </TITLE>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<script type="text/javascript" language="javascript">
var poststr = "?";
function addCustomer()
{
var url="http://localhost/Project/addCustomer.php";
if(window.XMLHttpRequest)
http = new XMLHttpRequest();
else if (window.ActiveXObject)
http = new ActiveXObject(Microsoft.XMLHTTP);
http.onreadystatechange = function()
{
alert(http.readyState);
if(http.readyState == 4)
{
alert(http.status)
if(http.status == 200)
{
response = http.responseText;
alert(response);
}
else
{
alert(http.status);
}
}
}
http.open("POST", url + poststr, true);
http.setRequestHeader("text");
http.send(null);
}
function reset()
{
document.updateCustomer.customer_name.value = "";
document.updateCustomer.customer_address.value = "";
document.updateCustomer.customer_contact_no.value = "";
}
function get(obj)
{
if((document.updateCustomer.customer_name.value == "") || (document.updateCustomer.customer_address.value == "") || (document.updateCustomer.customer_contact_no.value == ""))
{
alert("One or more fields are missing");
}
else
{
alert("ok");
poststr += "document.updateCustomer.customer_name.value" + "&document.updateCustomer.customer_address.value" + "&document.updateCustomer.customer_address.value";
}
addCustomer();
}
</script>
</HEAD>
<BODY onload="reset();">
<p align="center">
To add a new customer fill in the new customers name, address and contact number, then click <b>addCustomer</b>.
<p align="center">
To delete an existing customer, fill in the the details form the customers listed above, then click <b>deleteCustomer</b>.
<p>
<table border="1" align="center">
<tr>
<td align="center">Customer Name</td>
<td><input type="hidden" size="10"/></td>
<td align="center">Customer Address</td>
<td><input type="hidden" size="10"/></td>
<td align="center">Customer Contact Number</td>
</tr>
<tr>
<form name="updateCustomer" method="POST" action="$_SERVER['PHP_SELF']">
<td align="center"><input type="text" name="customer_name" id="customer_name" size="25" value=""/></td>
<td><input type="hidden" size="10"/></td>
<td align="center"><input type="text" name="customer_address" id="customer_address" size="25" value=""/></td>
<td><input type="hidden" size="10"/></td>
<td align="center"><input type="text" name="customer_contact_no" id="customer_contact_no" size="12" value=""/></td>
<td><input type="hidden" size="10"/></td>
<td align="center"><input type="button" name="addCustomer" value="addCustomer" onclick="get(this);"/></td>
<td><input type="hidden" size="10"/></td>
<td align="center"><input type="button" name="deleteCustomer" value="deleteCustomer" onclick="deleteCustomer();"/></td>
</form>
</tr>
</table>
</p>
<H1 align="center">ALLIED AUTO PARTS</H1>
<p>
<TABLE align="center">
<TR>
<TD align="center" colspan="6"><H3>Choose from the following funtions</H3></TD>
</TR>
<TR>
<TD><a href="ViewParts.php">View Parts</a></TD>
<TD><a href="Purchases.php">Purchases</a></TD>
<TD><a href="Sales.php">Sales</a></TD>
<TD><a href="UpdateParts.php">Add parts</a></TD>
<TD><a href="UpdateCustomer.php">Update Customer</a></TD>
<TD><a href="UpdateSupplier.php">Update Supplier</a></TD>
</TR>
</TABLE>
php script
Code:
<?php
$connect=pg_connect("dbname=AlliedAutoParts host=localhost user=User password=password");
if (!pg_connection_busy($connect))
{
$result=pg_query($connect, "insert into customer values($_POST['customer_name'], $_POST['customer_address'], $_POST['customer_contact_no'])");
}
echo "New customer added";
?>
rpjd
Comment