| | |
How to Insert/Edit data from TAG SELECT HTML Form to MySQL Database?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Jul 2009
Posts: 7
Reputation:
Solved Threads: 0
Hello everyone..it's me again..adindra
i have a problem :
i have 1 database name manipulasiphp, with 10 field (id,nama,email,alamat,umur,negara,universitas,jurusan,prodi,no_telp)
i have 1 HTML script and 1 PHP script
they're name are index.html and input.php
here's the script :
index.html
then input.php
in universitas html form,the html tag is select to show dropdown list
in jurusan html form,the html tag isradio
the question is :
"How to insert data to MySQL Database,from HTML Form with tag SELECT at Universitas field and tag type RADIO at Jurusan field??"
can you give me the right PHP script in my input.php file?
Hope you can help...
i have a problem :
i have 1 database name manipulasiphp, with 10 field (id,nama,email,alamat,umur,negara,universitas,jurusan,prodi,no_telp)
i have 1 HTML script and 1 PHP script
they're name are index.html and input.php
here's the script :
index.html
php Syntax (Toggle Plain Text)
<html> <head> <title>Form Calon Peserta Beasiswa Monbugakusho Jepang</title> </head> <body> <form method="post" action="input.php"> <table> <tr> <td>Nama</td> <td>: <input type="text" name="nama"></td> </tr> <tr> <td>Email</td> <td>: <input type="text" name="email"></td> </tr> <tr> <td>Alamat</td> <td>: <input type="text" name="alamat"></td> </tr> <tr> <td>Umur</td> <td>: <input type="text" name="umur" size="2" maxlength="3">tahun</td> </tr> <tr> <td>Negara</td> <td>: <input type="text" name="negara"></td> </tr> <tr> <td>Universitas</td> [B][COLOR="Red"]<td>: <select name="universitas[]"> <option value="1">Universitas Gadjah Mada,Yogyakarta</option> <option value="2">Institut Teknologi Bandung,Bandung</option> <option value="3">Universitas Indonesia,Jakarta</option> <option value="4">Institut Teknologi Sepuluh November,Surabaya</option> <option value="5">Universitas Airlangga,Surabaya</option> </td>[/COLOR][/B] </tr> <tr> [B][COLOR="Red"]<td>Jurusan :</td> <td><input type="radio" name="jurusan" value="1">Teknik Fisika <br><input type="radio" name="jurusan" value="2">Teknik Kimia <br><input type="radio" name="jurusan" value="3">Teknik Informatika <br><input type="radio" name="jurusan" value="4">MIPA </td>[/COLOR][/B] </tr> <tr> <td>Prodi</td> <td>: <input type="text" name="prodi"></td> </tr> <tr> <td>No Telpon</td> <td>: <input type="text" name="notelpon"></td> </tr> <tr> <td><input type="submit" name="submit" value="Daftar Beasiswa"></td> <td><input type="reset" name="reset" value="Ndak Jadi ahh.."></td> </tr> </table> </form> </body> </html>
then input.php
php Syntax (Toggle Plain Text)
<?php $host="localhost"; $usnm="root"; $pswd=""; $koneksi=mysql_connect("$host","$usnm","$pswd") or die ("Localhost tidak terkoneksi"); mysql_select_db("manipulasiphp",$koneksi); $input_nama=$_POST['nama']; $input_email=$_POST['email']; $input_alamat=$_POST['alamat']; $input_umur=$_POST['umur']; $input_negara=$_POST['negara']; $input_univ=$_POST['universitas']; $input_jurusan=$_POST['jurusan']; $input_prodi=$_POST['prodi']; $input_no_telp=$_POST['notelpon']; if((!empty($input_nama)) && (!empty($input_email)) && (!empty($input_alamat)) && (!empty($input_umur)) && (!empty($input_negara)) && (!empty($input_univ)) && (!empty($input_jurusan)) && (!empty($input_prodi)) && (!empty($input_no_telp))) { $query=mysql_query("INSERT INTO member (nama,email,alamat,umur,negara,universitas,jurusan,prodi,no_telp) VALUES ('$input_nama','$input_email','$input_alamat','$input_umur','$input_negara','$input_univ','$input_jurusan','$input_prodi','$input_no_telp')",$koneksi); echo "Calon Peserta Beasiswa baru telah terdaftar!!"; echo "<br>"; echo "<br>Untuk melihat peserta lainnya, klik <a href=\"view.php\">disini</a>"; } else { echo "<script>alert('Formulir pendaftaran harus diisi dengan lengkap');javascript:history.go(-1);</script>"; } ?>
in universitas html form,the html tag is select to show dropdown list
in jurusan html form,the html tag isradio
the question is :
"How to insert data to MySQL Database,from HTML Form with tag SELECT at Universitas field and tag type RADIO at Jurusan field??"
can you give me the right PHP script in my input.php file?
Hope you can help...
Last edited by adindra; Jul 9th, 2009 at 6:53 am.
Selects and Radios should be fine as long as you give them the value in witch you wich to be in the database.
If you were to insert the POSTed data from my little form you would insert "Male" into the database, whereas you are using 1, 2, 3 & 4 for your values.
Please make sure that you also
html Syntax (Toggle Plain Text)
<input type="radio" name="you_field" value="Male" />
Please make sure that you also
mysql_real_escape_string( $_POST['field_name'] ) as this will make sure MySql will not refuse any data given. Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
•
•
Join Date: Jul 2009
Posts: 7
Reputation:
Solved Threads: 0
•
•
•
•
Selects and Radios should be fine as long as you give them the value in witch you wich to be in the database.
If you were to insert the POSTed data from my little form you would insert "Male" into the database, whereas you are using 1, 2, 3 & 4 for your values.html Syntax (Toggle Plain Text)
<input type="radio" name="you_field" value="Male" />
Please make sure that you alsomysql_real_escape_string( $_POST['field_name'] )as this will make sure MySql will not refuse any data given.
you can try it yourself at your localhost,Josh,all of my script above..
hope you find out the solution..you can just copy-paste your tested script at this message's reply..
i need detail of the index.html and input.php..
Thank you Josh
•
•
Join Date: Jan 2008
Posts: 28
Reputation:
Solved Threads: 8
Without seeing how your database is set up (the design of your various fields), it seems like you may only have the 'universitas' and 'jarusan' fields to accept a different data type or you just have it set up as varchar(1). Either way, it would probably do you good to take real values, like Josh was saying, by putting meaningful text into the
Also, there are problems with your html.
Here's your 'universitas' select code:
Here's what it should look like:
You were missing the closing
Hope this helps.
value="" attributes.Also, there are problems with your html.
Here's your 'universitas' select code:
HTML Syntax (Toggle Plain Text)
<select name="universitas[]"> <option value="1">Universitas Gadjah Mada,Yogyakarta</option> <option value="2">Institut Teknologi Bandung,Bandung</option> <option value="3">Universitas Indonesia,Jakarta</option> <option value="4">Institut Teknologi Sepuluh November,Surabaya</option> <option value="5">Universitas Airlangga,Surabaya</option>
Here's what it should look like:
HTML Syntax (Toggle Plain Text)
<select name="universitas"> <option value="1">Universitas Gadjah Mada,Yogyakarta</option> <option value="2">Institut Teknologi Bandung,Bandung</option> <option value="3">Universitas Indonesia,Jakarta</option> <option value="4">Institut Teknologi Sepuluh November,Surabaya</option> <option value="5">Universitas Airlangga,Surabaya</option> </select>
You were missing the closing
</select> tag, and you probably didn't need to have an HTML array, which you specified by saying universitas[] .Hope this helps.
Last edited by jcacquiescent27; Jul 9th, 2009 at 3:28 pm.
•
•
Join Date: Jul 2009
Posts: 7
Reputation:
Solved Threads: 0
Thank you for everyone who have reply my message...it help me although a little..
But now i'm very happy coz this time..i solved the problem by myself!! what a great experience..
Let me tell you my ways to solve this problem :
I added 2 table in my database (database name is manipulasiphp). The name of two added tables are jurusan, and universitas
in jurusan table field contain id, and jurusan
in universitas table field contain id, and universitas
i fill the database directly through my phpMyAdmin, i filled the id and i filled the name of each university and name of each jurusan.
the main purpose here is fill directly the table, so i can output them in my index.php, exactly in my Form
then i edited my index.html become index.php, because i add php script in my HTML form in Universitas field form and Jurusan field form
here's the script :
index.php
you see that there are php script in Universitas form and Jurusan form, because i want to output the universitas table and jurusan table.
then after filled the form, i will go to input.php
here's the script :
input.php
it works!! and it also success added my member table in my manipulasiphp database
Thank you everyone..
PROBLEM SOLVED by adindra
But now i'm very happy coz this time..i solved the problem by myself!! what a great experience..
Let me tell you my ways to solve this problem :
I added 2 table in my database (database name is manipulasiphp). The name of two added tables are jurusan, and universitas
in jurusan table field contain id, and jurusan
in universitas table field contain id, and universitas
i fill the database directly through my phpMyAdmin, i filled the id and i filled the name of each university and name of each jurusan.
the main purpose here is fill directly the table, so i can output them in my index.php, exactly in my Form
then i edited my index.html become index.php, because i add php script in my HTML form in Universitas field form and Jurusan field form
here's the script :
index.php
php Syntax (Toggle Plain Text)
<?php // koneksi ke mysql mysql_connect("localhost","root",""); mysql_select_db("manipulasiphp"); ?> <form method="post" action="input.php"> <table> <tr> <td>Nama</td> <td>: <input type="text" name="nama"></td> </tr> <tr> <td>Email</td> <td>: <input type="text" name="email"></td> </tr> <tr> <td>Alamat</td> <td>: <input type="text" name="alamat"></td> </tr> <tr> <td>Umur</td> <td>: <input type="text" name="umur" size="2" maxlength="3"> tahun</td> </tr> <tr> <td>Negara</td> <td>: <input type="text" name="negara"></td> </tr> <tr> <td>Universitas</td> <td>: <select name="masuk_universitas"> <?php // query untuk menampilkan semua negara $query = "SELECT * FROM universitas"; $hasil = mysql_query($query); while ($data = mysql_fetch_array($hasil)) { // setiap negara yang dibaca dari tabel disisipkan ke tag <option></option> echo "<option value='".$data['id']."'>".$data['universitas']."</option>"; } ?> </select> </td> </tr> <tr> <td>Jurusan :</td> <td> <?php $query = "SELECT * FROM jurusan"; $hasil = mysql_query($query); while ($data = mysql_fetch_array($hasil)) { echo "<input type=\"radio\" name=\"masuk_jurusan\" value='".$data['id']."'>".$data['jurusan']." \n"; echo "<BR>"; } ?> </td> </tr> <tr> <td>Prodi</td> <td>: <input type="text" name="prodi"></td> </tr> <tr> <td>No Telp</td> <td>: <input type="text" name="notelpon"></td> </tr> <tr> <td><input type="submit" name="submit" value="Daftar Beasiswa" /></td> <td><input type="reset" name="reset" value="Ndak Jadi ah.." /></td> </tr> </table> </form>
you see that there are php script in Universitas form and Jurusan form, because i want to output the universitas table and jurusan table.
then after filled the form, i will go to input.php
here's the script :
input.php
php Syntax (Toggle Plain Text)
<?php $host="localhost"; $usnm="root"; $pswd=""; $koneksi=mysql_connect("$host","$usnm","$pswd") or die ("Localhost tidak terkoneksi"); mysql_select_db("manipulasiphp",$koneksi); $input_nama=$_POST['nama']; $input_email=$_POST['email']; $input_alamat=$_POST['alamat']; $input_umur=$_POST['umur']; $input_negara=$_POST['negara']; $input_univ=$_POST['masuk_universitas']; $input_jurusan=$_POST['masuk_jurusan']; $input_prodi=$_POST['prodi']; $input_no_telp=$_POST['notelpon']; if((!empty($input_nama)) && (!empty($input_email)) && (!empty($input_alamat)) && (!empty($input_umur)) && (!empty($input_negara)) && (!empty($input_univ)) && (!empty($input_jurusan)) && (!empty($input_prodi)) && (!empty($input_no_telp))) { $query=mysql_query("INSERT INTO member (nama,email,alamat,umur,negara,universitas,jurusan,prodi,no_telp) VALUES ('$input_nama','$input_email','$input_alamat','$input_umur','$input_negara','$input_univ','$input_jurusan','$input_prodi','$input_no_telp')",$koneksi); echo "Calon Peserta Beasiswa baru telah terdaftar!!"; echo "<br>"; echo "<br>Untuk melihat peserta lainnya, klik <a href=\"view.php\">disini</a>"; } else { echo "<script>alert('Formulir pendaftaran harus diisi dengan lengkap');javascript:history.go(-1);</script>"; } ?>
it works!! and it also success added my member table in my manipulasiphp database
Thank you everyone..
PROBLEM SOLVED by adindra
Yes but the original problem still stands, it was most liekly because MySql was triming the universities because the field will only accept one character.
For instance
But I'm glad you solved the problem. ;-)
For instance
varchar(1) will make this happen. You could have just changed it to varchar(100) .But I'm glad you solved the problem. ;-)
Posts should be like mini-skirts, long enough to cover enough, but not too long that you cover too much.
My Liveperson: http://liveperson.com/josh-connerty/
My Liveperson: http://liveperson.com/josh-connerty/
![]() |
Similar Threads
- how to connect ms access database to html webpage (JavaScript / DHTML / AJAX)
- Saving Images to a mysql database from an online form (PHP)
- html form to php mysql db insert for image (PHP)
- Parsing html form. (PHP)
- Php page containing html form to sql database (PHP)
- get data from HTML form (Java)
- retrieve data to DOM select from database (JavaScript / DHTML / AJAX)
- print html form (HTML and CSS)
- Insert & Edit Data in DataGrid (VB.NET)
Other Threads in the PHP Forum
- Previous Thread: I need some help with setting up a session.....
- Next Thread: Phpmyadmin
| Thread Tools | Search this Thread |
apache api array auto beginner binary broken cache cakephp checkbox class cms code codingproblem cron curl customizableitems database date display dynamic echo email error file files filter folder form format forms forum function functions gc_maxlifetime global google headmethod host href htaccess html image include insert ip javascript joomla limit link login mail malfunctioning memmory memory menu mlm multiple mysql nodes oop parameter parsing paypal pdf php phpmysql popup problem query radio random recursion recursiveloop remote script search select server sessions sms snippet source space sql static syntax system table trouble tutorial up-to-date update upload url validator variable video web youtube





