By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,751 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,751 IT Pros & Developers. It's quick & easy.

updating table using a form

P: 25
I am trying to submit entries in a form to a database. I am using
[code[
action="$_SERVER[PHP_SELF]"
[/code]
within my submission form and
Expand|Select|Wrap|Line Numbers
  1. $_POST['value-to-be-submitted']
  2.  
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
Expand|Select|Wrap|Line Numbers
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <? include("http://localhost/Project/customers.php") ?>
  3. <HTML>
  4.  <HEAD>
  5.   <TITLE> ALLIED AUTO PARTS </TITLE>
  6.   <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
  7.   <META NAME="Generator" CONTENT="EditPlus">
  8.   <META NAME="Author" CONTENT="">
  9.   <META NAME="Keywords" CONTENT="">
  10. <script type="text/javascript" language="javascript">
  11. var poststr = "?";
  12. function addCustomer()
  13.     { 
  14.     var url="http://localhost/Project/addCustomer.php";
  15.     if(window.XMLHttpRequest)
  16.     http = new XMLHttpRequest(); 
  17.     else if (window.ActiveXObject)
  18.     http  = new ActiveXObject(Microsoft.XMLHTTP); 
  19.     http.onreadystatechange = function()
  20.         { 
  21.         alert(http.readyState);
  22.         if(http.readyState == 4)
  23.             {
  24.             alert(http.status)
  25.             if(http.status == 200)
  26.                 {
  27.                 response = http.responseText;
  28.                 alert(response);
  29.                 }    
  30.             else    
  31.                 {
  32.                 alert(http.status);
  33.                 }    
  34.             } 
  35.         }
  36.         http.open("POST", url + poststr, true); 
  37.         http.setRequestHeader("text"); 
  38.         http.send(null); 
  39.     }
  40.  
  41. function reset()
  42.     {
  43.         document.updateCustomer.customer_name.value = "";
  44.         document.updateCustomer.customer_address.value = "";
  45.         document.updateCustomer.customer_contact_no.value = "";
  46.     }
  47.  
  48. function get(obj)
  49.     {
  50.     if((document.updateCustomer.customer_name.value == "") || (document.updateCustomer.customer_address.value == "") || (document.updateCustomer.customer_contact_no.value == ""))
  51.         {
  52.         alert("One or more fields are missing");
  53.         }
  54.         else
  55.             {
  56.             alert("ok");
  57.             poststr += "document.updateCustomer.customer_name.value" + "&document.updateCustomer.customer_address.value" + "&document.updateCustomer.customer_address.value";
  58.             }
  59.             addCustomer();
  60.     }
  61. </script>
  62.  
  63.   </HEAD>
  64.     <BODY onload="reset();">
  65. <p align="center">
  66. To add a new customer fill in the new customers name, address and contact number, then click <b>addCustomer</b>.
  67. <p align="center">
  68. To delete an existing customer, fill in the the details form the customers listed above, then click <b>deleteCustomer</b>.
  69. <p>
  70. <table border="1" align="center">
  71. <tr>
  72. <td align="center">Customer Name</td>
  73. <td><input type="hidden" size="10"/></td>
  74. <td align="center">Customer Address</td>
  75. <td><input type="hidden" size="10"/></td>
  76. <td align="center">Customer Contact Number</td>
  77. </tr>
  78. <tr>
  79. <form name="updateCustomer" method="POST" action="$_SERVER['PHP_SELF']">
  80. <td align="center"><input type="text" name="customer_name" id="customer_name" size="25" value=""/></td>
  81. <td><input type="hidden" size="10"/></td>
  82. <td align="center"><input type="text" name="customer_address" id="customer_address" size="25" value=""/></td>
  83. <td><input type="hidden" size="10"/></td>
  84. <td align="center"><input type="text" name="customer_contact_no" id="customer_contact_no" size="12" value=""/></td>
  85. <td><input type="hidden" size="10"/></td>
  86. <td align="center"><input type="button" name="addCustomer" value="addCustomer" onclick="get(this);"/></td>
  87. <td><input type="hidden" size="10"/></td>
  88. <td align="center"><input type="button" name="deleteCustomer" value="deleteCustomer" onclick="deleteCustomer();"/></td>
  89. </form>
  90. </tr>
  91. </table>
  92. </p>
  93. <H1 align="center">ALLIED AUTO PARTS</H1>
  94. <p>
  95. <TABLE align="center">
  96. <TR>
  97.     <TD align="center" colspan="6"><H3>Choose from the following funtions</H3></TD>
  98. </TR>
  99. <TR>
  100.     <TD><a href="ViewParts.php">View Parts</a></TD>
  101.     <TD><a href="Purchases.php">Purchases</a></TD>
  102.     <TD><a href="Sales.php">Sales</a></TD>
  103.     <TD><a href="UpdateParts.php">Add parts</a></TD>
  104.     <TD><a href="UpdateCustomer.php">Update Customer</a></TD>
  105.     <TD><a href="UpdateSupplier.php">Update Supplier</a></TD>
  106. </TR>
  107. </TABLE>
  108.  

php script
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $connect=pg_connect("dbname=AlliedAutoParts host=localhost user=User password=password");
  3. if (!pg_connection_busy($connect))
  4.     {
  5.     $result=pg_query($connect, "insert into customer values($_POST['customer_name'], $_POST['customer_address'], $_POST['customer_contact_no'])");
  6.     }
  7.     echo "New customer added";
  8. ?>
  9.  
Using alerts to debug I am getting OK,1, 2, 3, 4, 200, "blank alert".

rpjd
Apr 28 '07 #1
Share this Question
Share on Google+
2 Replies


100+
P: 136
Hi,

please put this line for getting the error, it will be easier if u r getting the error printed in ur page.

[PHP]ini_set('display_errors', '1');[/PHP]

please let us know whats the error u r getting.

susen
Apr 28 '07 #2

P: 25
Hi,

please put this line for getting the error, it will be easier if u r getting the error printed in ur page.

[PHP]ini_set('display_errors', '1');[/PHP]

please let us know whats the error u r getting.

susen
I seemed to have solved the error here
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. $connect=pg_connect("dbname=AlliedAutoParts host=localhost user=User password=password");
  3. if (!pg_connection_busy($connect))
  4.     {
  5.     $result=pg_query($connect, "insert into customer values('$customer_name', '$customer_address', '$customer_contact_no')");
  6.     }
  7.     echo "New customer added";
  8. ?>
  9.  
Apr 28 '07 #3

Post your reply

Sign in to post your reply or Sign up for a free account.