Connecting Tech Pros Worldwide Forums | Help | Site Map

Inserting into Access via php.

Newbie
 
Join Date: Jun 2008
Posts: 1
#1: Jun 30 '08
I'm doing an online registration form and using ODBC to connect to my database. I'm new to programming thus I do not know most of the advance features for php and Access. I need help in inserting data into the table in Access. I created a .php file to insert the code but it does not work. Here is the code
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. $name = $_POST['name'];
  3. $admin = $_POST['admin'];
  4. $gender = $_POST['gender'];
  5. $address = $_POST['address'];
  6. $hometel = $_POST['hometel'];
  7. $hp = $_POST['hp'];
  8. $email = $_POST['email'];
  9. $course = $_POST['course'];
  10. $year = $_POST['year'];
  11. $path = $_POST['path'];
  12. $title = $_POST['title'];
  13. $supervisor = $_POST['supervisor'];
  14. $odbc = odbc_connect('FYP', '', '') or die('Could not connect to ODBC database!');
  15. $query = "INSERT INTO fyp (Name, AdminNumber, Gender, Address, Hometelephone, MobilePhone, Email, AcadCourse, Year, Path ,Projecttitle, ProjectSupervisor) VALUES ("$name","$admin","$gender","$address","$hometel","$hp","$email","$course", "$year","$path","$title","$supervisor")";
  16. $result = odbc_exec($odbc, $query) or die (odbc_errormsg());
  17. odbc_close($odbc);
  18. ?>
If its required, I can post my registration form here. Thanks.

Moderator
 
Join Date: Feb 2008
Location: Beauly, near Inverness, Scotland
Posts: 1,576
#2: Jul 1 '08

re: Inserting into Access via php.


Hi. I have moved this thread from the Access forum, as one thing we Access bods don't tend to be is PHP experts (at least not as far as I know). The INSERT INTO seems fine, so I'm happy to hand this one to the PHP experts for their views...

By the way, saying 'it does not work' is not helpful to any of us - do you get an error message when you try to run it, if so at what line, and what debugging have you done for yourself? It is best that we don't play 'guess the error' when reviewing your code.

-Stewart
Markus's Avatar
Moderator
 
Join Date: Jun 2007
Location: York, England, with wolves.
Posts: 4,949
#3: Jul 1 '08

re: Inserting into Access via php.


Do you receive any error messages?
What does happen? What doesn't happen?

- oh. I see Stew has already asked that.

Also, you're inserting unescaped data into a datanase - not a good idea!
Read about mysql injection.

Kind regards
Reply