| | |
Problem inserting data into Access database via php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2008
Posts: 8
Reputation:
Solved Threads: 0
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
And this is the code that I'm trying to use to submit into the database.
This is the code for the form and confirmation page
PHP Syntax (Toggle Plain Text)
<?php error_reporting(E_ALL ^ E_NOTICE); ?> <?php function checkphone() { global $tel; $phone = $_POST['hometel']; if (!preg_match('/^[0-9]{8}$/', $phone)) { $tel = '<font color="red"><b>Your telephone number is invalad</b></font>'; $GLOBALS['tel'] = $tel; } else{ $GLOBALS['showtel'] = "true"; } } function checkemail() { global $mail; $email = $_POST['email']; if (!preg_match('/^([a-zA-Z0-9])+([a-zA-Z0-9\.\\+=_-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9\._-]+)+$/', $email)) { $mail = '<font color="red"><b>Your Email is invalid</b></font>'; $GLOBALS['mail'] = $mail; } else { $GLOBALS['showmail'] = "true"; } } if($_POST['submit']) { checkphone(); checkemail(); } if(!$showtel||!$showmail){ ?> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>FYP</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <p align="center">Name: <input type="text" name="username" /> </p> <p align="center">Admin No.: <input type="text" name="admin" /> </p> <p align="center">Gender: <select name="gender"> <option value="male" selected>Male</option> <option value="female">Female</option> </select> </p> <p align="center">Address: <textarea name="address" cols="40"></textarea /> </p> <p align="center">Home Phone: <input type="text" name="hometel" /> <br> <?php echo $tel; ?> </p> <p align="center">Mobile Phone: <input type="text" name="hp" /> </p> <p align="center">Contact Email: <input type="text" name="email" /> <br> <?php echo $mail; ?> </p> <p align="center">Course: <select name="course"> <option value="ECC">ECC</option> </select> </p> <p align="center">Acad Year: <input type="text" name="year" /> </p> <p align="center">Path: <select name="path"> <option value="1">B1</option> <option value="2">B2</option> <option value="3">B3</option> </select> </p> <p align="center">Project Title: <textarea name="title" cols="40"></textarea> </p> <p align="center">Project Supervisor: <select name="supervisor"> <option value="Mr. Stephen Liew K C" selected>Mr. Stephen Liew K C</option> <option value="Mr. Steven Ng">Mr. Steven Ng</option> </select> </p> <p align="center"> <input name="submit" type="submit" /> </p> </form> <?php } else { ?> <form action="datasubmit.php" method="post"> <?php echo'<div align="center">'; echo '<p>Name: '.$_POST["username"].' <br />'; echo 'Admin No.: '.$_POST["admin"].' <br />'; echo 'Gender: '.$_POST["gender"].' <br />'; echo 'Address: '.$_POST["address"].' <br />'; echo 'Home Phone: '.$_POST["hometel"].' <br />'; echo 'Handphone: '.$_POST["hp"].' <br />'; echo 'Contact Email: '.$_POST["email"].' <br />'; echo 'Course: '.$_POST["course"].' <br />'; echo 'Acad Year: '.$_POST["year"].' <br />'; echo 'Path: '.$_POST["path"].' <br />'; echo 'Project title:'.$_POST["title"].' <br />'; echo 'Project Supervisor: '.$_POST["supervisor"].' <br />'; ?> <p> <input type="submit" name="Submit" value="Submit"> </form> </p> <p> <input name="button" type=button onClick=window.history.back() value=Back back> </p> </div> <?php }?> </body> </html>
And this is the code that I'm trying to use to submit into the database.
PHP Syntax (Toggle Plain Text)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Untitled Document</title> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> </head> <body> <?php $username = $_POST['username']; $admin = $_POST['admin']; $gender = $_POST['gender']; $address = $_POST['address']; $phone = $_POST['hometel']; $hp = $_POST['hp']; $email = $_POST['email']; $course = $_POST['course']; $year = $_POST['year']; $path = $_POST['path']; $title = $_POST['title']; $supervisor = $_POST['supervisor']; echo "Data has been submitted"; function Enter_New_Entry($username,$admin) { if(!$cnx = odbc_connect( 'FYP' , 'root', '' ))die("error with connection"); $SQL_Exec_String = "Insert Into rank (name, admin, gender, address, hometel, hp, email, course, year, path, title, supervisor ) Values ('$username', '$admin', '$gender', '$address', '$phone', '$hp', '$email', '$course', '$year', '$path', '$title', '$supervisor')"; $cur= odbc_exec( $cnx, $SQL_Exec_String ); if (!$cur) { Error_handler( "Error in odbc_exec( no cursor returned ) " , $cnx ); } odbc_close( $cnx); } Enter_New_Entry($username,$admin); ?> </body> </html>
•
•
Join Date: Jul 2008
Posts: 8
Reputation:
Solved Threads: 0
It seems that the register_global being off could be the problem for my code. I've tried turning register_global on and using session, it manage to insert the username and admin into the database. However everything starting with gender is being submitted as blank. I've read online that turning register_global is quite dangerous. Is there any way to get around this problem ?
Last edited by joeey; Jul 8th, 2008 at 12:28 am.
•
•
•
•
Thanks for the advice vick_rawat but it seems to be working now. I'm using $_SESSION['username'] = $username to get it working. Also is there any tutorial you can reccomand on updating the database?
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
What do you mean by 'update database via a form than using codes' ? Maybe this can help.
http://www.configure-all.com/php_access.php
http://www.configure-all.com/php_access.php
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
•
•
Join Date: Jul 2008
Posts: 8
Reputation:
Solved Threads: 0
Sorry for causing a misunderstanding, I think the right word I should use is modify. I would like to modify my contents in the database via a website instead of typing the values into the codes. For example if I made a mistake and typed 110 for my age, I would like to have a function where I can show the entry with the mistake and correct it in a webpage.
![]() |
Other Threads in the PHP Forum
- Previous Thread: Paypal integration with website
- Next Thread: new folder
| Thread Tools | Search this Thread |
ajax apache api array beginner beneath binary broadband broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date decode display dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla limit link login loop mail match md5 menu mlm multiple mysql mysql_real_escape_string oop paypal pdf php problem protocol query radio random recursion regex remote script search server session sessions sms smtp soap source space sql strip_tags survey syntax system table tutorial undefined update upload url validator variable video virus votedown web window.onbeforeunload=closeme; xml youtube






