First, create a MySQL database with the following table
CREATE TABLE IF NOT EXISTS 'data' ( 'id' int(10) unsigned NOT NULL, 'english_name' varchar(50) collate utf8_unicode_ci NOT NULL, 'tel_number' varchar(8) collate utf8_unicode_ci NOT NULL, 'email_address' varchar(50) collate utf8_unicode_ci NOT NULL, 'gender' varchar(1) collate utf8_unicode_ci NOT NULL, 'age' varchar(10) collate utf8_unicode_ci NOT NULL, 'region' varchar(10) collate utf8_unicode_ci NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
Prepare a update.php for the MySQL connection.
<?php $english_name = $_POST['EnglishName']; $tel_number = $_POST['TelNumber']; $email_address = $_POST['EmailAddress']; $gender = $_POST['Gender']; $age = $_POST['Age']; $region = $_POST['Region']; mysql_connect("[mysql_server]", "[username]", "[password]") or die ('Error: ' . mysql_error()); mysql_select_db("[database_name]"); $query="INSERT INTO data (english_name, tel_number, email_address, gender, age, region) VALUES ("; $query.="'".$english_name."', "; $query.="'".$tel_number."', "; $query.="'".$email_address."', "; $query.="'".$gender."', "; $query.="'".$age."', "; $query.="'".$region."')"; mysql_query($query) or die ('Error updating database'); echo "Record is inserted."; ?>
Prepare the form.php
<html> <head> <title>Simple PHP Form</title> </head> <body> <form method="post" action="update.php"> <table> <tr> <td>English Name:</td> <td><input type="text" name="EnglishName" size="50" /></td> <td>Tel Number:</td> <td><input type="text" name="TelNumber" size="8" /></td> </tr> <tr> <td>Email Address:</td> <td><input type="text" name="EmailAddress" size="50" /></td> <td>Gender:</td> <td><input type="radio" name="Gender" value="M" checked="checked" />M<input type="radio" name="Gender" value="F" />F</td> </tr> <tr> <td>Age:</td> <td colspan="3"> <input type="radio" name="Age" value="Under 18" checked="checked" />Under 18 <input type="radio" name="Age" value="18-23" />18-23 <input type="radio" name="Age" value="24-30" />24-30 <input type="radio" name="Age" value="31-40" />31-40 <input type="radio" name="Age" value="Over 40" />Over 40 </td> </tr> <tr> <td>Region:</td> <td> <select name="Region"> <option value="N/A">N/A</option> <option value="HK">Hong Kong</option> <option value="KLN">Kowloon</option> </select> </td> </tr> <tr> <td colspan="4"><input type="Submit" value="Submit" /></td> </tr> </table> </form> </body> </html>
Done =)
Thanks you for share, any advice for develop a drop down menu?
LikeLike
I think u can refer to this tutorial.
Simple Drop-Down Menu v2.0
hope this help =)
LikeLike
A very neat and comprehensive example.
I noticed you have a few Android blogs.
Any chance you could provide some code to show how it is possible to update or add a record to a MySQL table.
Would it be possible to write a generalised one so that one could create a form on the android, which could be reference any table you have.
Thanks
Richard
LikeLike
Hi Richard,
i haven’t tried that before. but i think you can refer to the following post.
Hello Android – Connecting to MySQL database
Regards,
Kit
LikeLike
if your having issues with the mysql code this also works
just replace “MYDB with the database that your putting the table in
LikeLiked by 1 person
Thanks Blake. =)
LikeLike
My radio group looks like this:
Are you part of the corporate/group challenge?
Register below:
Bank of America
Rancho Simi Recreation and Park District
Simi Valley Hospital
City of Simi Valley
Simi Valley Unified School District
Bank of America
Rancho Simi Recreation and Park District
Simi Valley Hospital
City of Simi Valley
Simi Valley Unified School District
What is wrong with this code? What do I need to do to get it into the database?
Linda
LikeLike
Hi Linda,
the code cannot be shown in your last comment, could you post that again as mentioned @ Syntax Highlight?
Or you can send the file to my email.
Regards,
Kit
LikeLike
This is real good, it solved my problem, Great Job
LikeLike
Thanks for your comment. =)
LikeLike
One more help plz:
1.I need to be able to login into mysql database using one time login password, let say i generate a password which can be valid only for two hours, then after that it expires, until when i use another one.
LikeLike
Sorry, i didn’t get your problem. Can u elaborate more?
LikeLike
Hi ykyuen, here is the elaboration: I need to set a login password in mysql table, which will expire after a certain time, let say 2 hours only. Is there any software or script which ca be able to generate such type of passwords? I am developing online quiz so i need users to use passwords only within a limited time of session, there after expires and request another pasword. I hope now it is clear.
LikeLike
You can add a created at column in the table you store the login name and password so that you can store the created timestamp when the user requests the password.
When the user attempts to login, you could compared the current timestampe and the stored created at timestamp.
If the difference is bigger than 2 hours, Reject his login request.
Does it sound feasible?
LikeLike
how can i create database for checkbox input,when form is submitted and then inserted to database, my code is below..plz guide me here
LikeLike
nice tutorial its very helpful to me
LikeLike