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

<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]<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>[/B]
</tr>
<tr>
[B]<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>[/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
$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...

Selects and Radios should be fine as long as you give them the value in witch you wich to be in the database.

<input type="radio" name="you_field" value="Male" />

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 mysql_real_escape_string( $_POST['field_name'] ) as this will make sure MySql will not refuse any data given.

Selects and Radios should be fine as long as you give them the value in witch you wich to be in the database.

<input type="radio" name="you_field" value="Male" />

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 mysql_real_escape_string( $_POST['field_name'] ) as this will make sure MySql will not refuse any data given.

thanks for reply..but, i'm sorry it didn't work..it will work if the value is only one.But it didn't work if there are more than 1 value..

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

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 value="" attributes.

Also, there are problems with your html.

Here's your 'universitas' select code:

<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:

<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.

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

<?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
$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 varchar(1) will make this happen. You could have just changed it to varchar(100) .

But I'm glad you solved the problem. ;-)

i want a full registration form tag and after submitting this open it by user id and password tag

Member Avatar for diafol

Start your own thread. Include your code. State where you're going wrong. Mention anything else you've tried and any error messages that you get. If you're looking for free code. Rearrange these letters: fcuk fof. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.