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

Help connecting php to a MS Access database

P: 8
Hello all,

I am new to php and I can't seem to get some code to insert information into a Access database. I am running Apache 2.2 server with php 5.1.2 and on a Windows XP SP2 platform. Here is the code I am attempting to get running, if someone is intrested in helping a new php person out.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $Fname = $_POST["name"];
  3. $Fphone = $_POST["phone"];
  4. $Fproblem = $_POST["problem"];
  5. $Fdate = date("m/d/Y");
  6. if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
  7. ?>
  8.  
  9. <html>
  10. <head>
  11. <title>IT Issues</title>
  12. </head>
  13. <body bgcolor="#00FFFF" onLoad="self.focus();document.IssueAdd.name.focus()" >
  14. <h1 align="center">Tuthill Transport Technologies</h1>
  15. <hr>
  16. <h2><i><font size="5" face="Arial">IT Trouble Report</font></i></h2>
  17. <!-- Begin form code --> 
  18.  
  19. <tr>
  20. <td width="100%" valign="top">
  21.  <form name="IssueAdd" method="post" action="<?php echo $PHP_SELF;?>">
  22.     <font size="3" face="Arial"> Name: <input type="text" name="name" tabindex=1 maxlength="20"></font> 
  23.      <br>
  24.     <font size="3" face="Arial"> Phone: <input type="text" name="phone" tabindex=2 maxlength="5"></font> 
  25. </td>
  26. </tr>
  27.  
  28. <tr>
  29. <br>
  30. <td width="100%" valign="top"> <br></td>
  31. </tr>
  32.  
  33. <tr>
  34. <td width="100%" valign="top">
  35.     <font size="3" face="Arial">
  36.     <q>Please give a summary of the problem, and any cause that you may know of.</q>
  37.     </font> <br>    <textarea name="problem" tabindex=3 rows="10" cols="70"></textarea>
  38. </td>
  39. </tr>
  40.  
  41. <tr>
  42. <br>
  43. <td width="100%" valign="top"> <br></td>
  44. </tr>
  45.  
  46. <tr>
  47. <br>
  48. <td width="100%" valign="top">
  49.      <input type="submit" name="submit" tabindex=4 value="Submit Request">
  50. </td>
  51. </tr>
  52.  
  53. <tr>
  54. <br>
  55. <td width="100%" valign="top"> <br></td>
  56. </tr>
  57.  
  58. </form> 
  59. </body>
  60. </html>
  61. <?
  62. } else {
  63. echo "<b>Your request has been sent to the IT group as:</b><br/>";
  64. echo "<br />";
  65. echo "Contact name: ".$Fname." at ".$Fphone."<br />";
  66. echo "<br />";
  67. echo "To resolve: <br />";
  68. echo $Fproblem." <br />";
  69. echo "<br />";
  70. echo "Submission Date: ";
  71. //echo date("m/d/Y");
  72. echo $Fdate;
  73. echo "<br />";
  74. echo "Submission Time ";
  75. echo date("h:i:s");
  76. echo "<br />";
  77. echo "<br />";
  78. echo "<br />";
  79. echo "Thank You";
  80.  
  81. $db = 'C:\\xampp\\htdocs\\ITrequest\\PC_PROBLEMS.mdb';
  82. $conn = new COM('ADODB.Connection') or exit('Cannot start ADO.');
  83. //$con=odbc_connect("ITrequest","","") or exit('Cannot open with ODBC');
  84. $conn->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=$db") or exit('Cannot open with Jet.');
  85. //$conn->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=$db") or exit('Cannot open with driver.');
  86. $sql = "INSERT INTO PROBLEMS(USER,phone,SUMMARY OF REPORT,date) VALUES('$Fuser','$Fphone','$Fproblem','$Fdate'])";
  87. $rs = $conn->Execute($sql);
  88.  
  89. }
  90. ?>
  91.  
As you can see I have made several attempts to connect with different drivers, but I have had no sucess with any.

Thank You
Oct 29 '07 #1
Share this Question
Share on Google+
2 Replies

code green
Expert 100+
P: 1,726
Can you break the problem down a little more.
I am not sure if you mean the connection is failing or the INSERT query.
I have used the COM class to connect to Access before so I know it generates error messages (albeit not very helpful).
What errors are you getting?.
Can you connect via ODBC?
Oct 30 '07 #2

P: 8
Yes,

I was able to connect using ODBC.

Thank You !!!
Oct 30 '07 #3

Post your reply

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