View Single Post
Join Date: Jul 2008
Posts: 8
Reputation: joeey is an unknown quantity at this point 
Solved Threads: 0
joeey joeey is offline Offline
Newbie Poster

Problem inserting data into Access database via php

 
0
  #1
Jul 6th, 2008
Hi everyone, I'm new to programming and I'm doing an online registration form for my project. I have a problem with my form. After submitting my form, a confirmation page will show up with the information displayed on the page. When I click submit on the confirmation page, It is suppose to submit the data into the database. However I get HTTP 500 internal error The page cannot be displayed. I'm using ODBC for my connection and the connection is working as I can submit and retrieve information from the database using codes for other projects.
This is the code for the form and confirmation page


  1. <?php
  2. error_reporting(E_ALL ^ E_NOTICE);
  3. ?>
  4. <?php
  5.  
  6. function checkphone() {
  7. global $tel;
  8. $phone = $_POST['hometel'];
  9. if (!preg_match('/^[0-9]{8}$/', $phone)) {
  10. $tel = '<font color="red"><b>Your telephone number is invalad</b></font>';
  11. $GLOBALS['tel'] = $tel; }
  12. else{
  13. $GLOBALS['showtel'] = "true";
  14. }
  15. }
  16.  
  17.  
  18. function checkemail() {
  19. global $mail;
  20. $email = $_POST['email'];
  21. if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) {
  22. $mail = '<font color="red"><b>Your Email is invalid</b></font>';
  23.  
  24. $GLOBALS['mail'] = $mail; }
  25. else
  26. {
  27. $GLOBALS['showmail'] = "true";
  28. }
  29. }
  30.  
  31. if($_POST['submit'])
  32. {
  33. checkphone();
  34. checkemail();
  35. }
  36. if(!$showtel||!$showmail){
  37. ?>
  38. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  39. <html>
  40. <head>
  41. <title>FYP</title>
  42. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  43. </head>
  44.  
  45. <body>
  46. <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
  47. <p align="center">Name:
  48. <input type="text" name="username" />
  49. </p>
  50. <p align="center">Admin No.:
  51.  
  52. <input type="text" name="admin" />
  53. </p>
  54. <p align="center">Gender:
  55. <select name="gender">
  56. <option value="male" selected>Male</option>
  57. <option value="female">Female</option>
  58. </select>
  59. </p>
  60. <p align="center">Address:
  61. <textarea name="address" cols="40"></textarea />
  62. </p>
  63. <p align="center">Home Phone:
  64. <input type="text" name="hometel" /> <br>
  65. <?php echo $tel; ?>
  66. </p>
  67. <p align="center">Mobile Phone:
  68. <input type="text" name="hp" />
  69. </p>
  70. <p align="center">Contact Email:
  71. <input type="text" name="email" /> <br>
  72. <?php echo $mail; ?>
  73. </p>
  74. <p align="center">Course:
  75. <select name="course">
  76. <option value="ECC">ECC</option>
  77. </select>
  78. </p>
  79. <p align="center">Acad Year:
  80. <input type="text" name="year" />
  81. </p>
  82. <p align="center">Path:
  83. <select name="path">
  84. <option value="1">B1</option>
  85. <option value="2">B2</option>
  86. <option value="3">B3</option>
  87. </select>
  88. </p>
  89. <p align="center">Project Title:
  90. <textarea name="title" cols="40"></textarea>
  91. </p>
  92. <p align="center">Project Supervisor:
  93. <select name="supervisor">
  94. <option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option>
  95. <option value="Mr. Steven Ng">Mr. Steven Ng</option>
  96. </select>
  97. </p>
  98. <p align="center">
  99. <input name="submit" type="submit" />
  100. </p>
  101.  
  102. </form>
  103.  
  104. <?php
  105. } else {
  106. ?>
  107. <form action="datasubmit.php" method="post">
  108. <?php
  109.  
  110. echo'<div align="center">';
  111. echo '<p>Name: '.$_POST["username"].' <br />';
  112. echo 'Admin No.: '.$_POST["admin"].' <br />';
  113. echo 'Gender: '.$_POST["gender"].' <br />';
  114. echo 'Address: '.$_POST["address"].' <br />';
  115. echo 'Home Phone: '.$_POST["hometel"].' <br />';
  116. echo 'Handphone: '.$_POST["hp"].' <br />';
  117. echo 'Contact Email: '.$_POST["email"].' <br />';
  118. echo 'Course: '.$_POST["course"].' <br />';
  119. echo 'Acad Year: '.$_POST["year"].' <br />';
  120. echo 'Path: '.$_POST["path"].' <br />';
  121. echo 'Project title:'.$_POST["title"].' <br />';
  122. echo 'Project Supervisor: '.$_POST["supervisor"].' <br />';
  123.  
  124. ?>
  125. <p>
  126. <input type="submit" name="Submit" value="Submit">
  127. </form>
  128. </p>
  129. <p>
  130. <input name="button" type=button onClick=window.history.back() value=Back back>
  131. </p>
  132. </div>
  133.  
  134. <?php }?>
  135.  
  136. </body>
  137. </html>


And this is the code that I'm trying to use to submit into the database.

  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <head>
  4. <title>Untitled Document</title>
  5. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  6. </head>
  7. <body>
  8. <?php
  9. $username = $_POST['username'];
  10. $admin = $_POST['admin'];
  11. $gender = $_POST['gender'];
  12. $address = $_POST['address'];
  13. $phone = $_POST['hometel'];
  14. $hp = $_POST['hp'];
  15. $email = $_POST['email'];
  16. $course = $_POST['course'];
  17. $year = $_POST['year'];
  18. $path = $_POST['path'];
  19. $title = $_POST['title'];
  20. $supervisor = $_POST['supervisor'];
  21. echo "Data has been submitted";
  22.  
  23. function Enter_New_Entry($username,$admin) {
  24.  
  25.  
  26. if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection");
  27. $SQL_Exec_String = "Insert Into rank (name, admin, gender, address, hometel, hp, email, course, year, path, title, supervisor )
  28. Values ('$username', '$admin', '$gender', '$address', '$phone', '$hp', '$email', '$course', '$year', '$path', '$title', '$supervisor')";
  29.  
  30. $cur= odbc_exec( $cnx, $SQL_Exec_String );
  31. if (!$cur) {
  32. Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx );
  33. }
  34.  
  35. odbc_close( $cnx);
  36. }
  37. Enter_New_Entry($username,$admin);
  38. ?>
  39.  
  40. </body>
  41. </html>
Reply With Quote