I try to record data from the following code: input_data_mhs.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include ("server.php"); include ("menu.php"); echo " <h1 align=\"center\">Input Data Mahasiswa</h1> <form method=\"post\" action=\"input_data.php\" ENCTYPE=\"MULTIPART/FORM-DATA\"> <table border=\"0\" align=\"center\"> <tr> <td>Nim</td> <td><input type=\"text\" name=\"nim\"></td> </tr> <tr> <td>Nama</td> <td><input type=\"text\" name=\"nama\"></td> </tr>"; echo " <tr> <td>Jenis Kelamin</td> <td><input type=\"radio\" name=\"jk\" value\"1\">Laki</td> </tr> <tr> <td></td> <td><input type=\"radio\" name=\"jk\" value=\"0\">Perempuan</td> </tr>"; echo " <tr> <td>Angkatan</td> <td><select name=\"angkatan\"> <option value=\"kosong\"> Tahun </option>"; $tahun = (integer) date ("Y"); for ($i = $tahun; $i>($tahun - 6); $i--) { echo "<option value=\"$i\">$i"; } echo "</option> </select><td></tr>"; echo " <tr> <td>Jurusan</td> <td><select name=\"jurusan\"> <option value=\"kosong\">---Program Studi--- </option>"; $koneksi = mysql_connect($host, $user, $pass) or die (mysql_error()); mysql_select_db($db, $koneksi) or die (mysql_error()); $query = mysql_query("select * from jurusan order by kode_jurusan", $koneksi) or die (mysql_error()); while ($row_nim = mysql_fetch_array($query)) { echo "<option value = \"$row_nim[0]\" > $row_nim[1] </option>"; } echo "</td>"; echo " <tr> <td>Foto</td> <td><input type=\"FILE\" accept=image/jpeg name=\"foto\"></td></tr>"; echo " <tr> <td><input type=\"submit\" value=\"submit\"></td> <td><input type=\"reset\" value=\"reset\"></td> </tr> </table> "; ?> PHP: After I typed in some input then it will takes me to this code: input_data.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include ("server.php"); include ("menu.php"); // kata yang di ucwords() akan mempunyai huruf pertamanya // huruf kapital // walaupun sengaja di tulis dalam huruf kecil //$nama = ucwords($nama); $koneksi = mysql_connect ($host, $user, $pass) or die (mysql_error()); mysql_select_db($db) or die (mysql_error()); // default to no error message $message = ''; if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else $nim = $_POST['nim']; if (!$_POST['nama']) $message .= 'Required parameter nama is missing.<br />'; else $nama = $_POST['nama']; if (!$_POST['jk']) $message .= 'Required parameter jk is missing.<br />'; else $jk = $_POST['jk']; if (!$_POST['jurusan']) $message .= 'Required parameter jurusan is missing.<br />'; else $jurusan = $_POST['jurusan']; if (!$_FILES['foto']) $message .= 'Required parameter foto is missing.<br />'; else $foto = $_FILES['foto']; //etc. for each parameter if ($message) // we have an error, so display it { echo $message; // do whatever // and redisplay the form include ("input_data_mhs_form.php"); }else // no errors, so process the data { // Copy file ke dalam folder ../image move_uploaded_file( $_FILES['foto']['tmp_name'], '../image/' . $_FILES['foto']['name'] ) echo $nim; echo $nama; echo $jk; echo $jurusan; echo $foto; // Karena hanya memasukkan informasi mahasiswa maka // untuk pengisian nilai dan grade di buatkan form tersendiri // sehingga pada file ini dikosongi mysql_query ("INSERT into mhs (`nim`, `nama`, `jk`, `jurusan`, `foto`) VALUES (`$nim`, `$nama`, `$jk`, `$jurusan`, `$foto`)", $koneksi) or die (mysql_error()); } ?> PHP: I typed in: echo $nim; echo $nama; echo $jk; echo $jurusan; echo $foto; to see the result from the previous code. Yet, nothing printed. Can anyone help me so that I can see the result from input_data_mhs.php typed in data?
What you need to do is print them out with the post as you have not assigned the post values to the variables your trying to echo. e.g. print $_POST['nim']; Adam
I make some changes in the following part of input_data.php // default to no error message $message = ''; if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else $nim = $_POST['nim']; print $_POST['nim']; if (!$_POST['nama']) $message .= 'Required parameter nama is missing.<br />'; else $nama = $_POST['nama']; print $_POST['nama']; if (!$_POST['jk']) $message .= 'Required parameter jk is missing.<br />'; else $jk = $_POST['jk']; print $_POST['jk']; if (!$_POST['jurusan']) $message .= 'Required parameter jurusan is missing.<br />'; else $jurusan = $_POST['jurusan']; print $_POST['jurusan']; if (!$_FILES['foto']) $message .= 'Required parameter foto is missing.<br />'; else $foto = $_FILES['foto']; print $_FILES['foto']; PHP: The result is still about the same. Nothing appear. Maybe you could check it yourself in: http://www.davesolution.com/xYzAbJ/input_data_mhs.php. Type in some datas and see the result.
Include the {} braces after the else if you have compound statement under it. -------------- // default to no error message $message = ''; if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else { $nim = $_POST['nim']; print $_POST['nim']; } ---------------------The simple way is ----------------- if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else print $_POST['nim']; ---------------------- The proper way ------------------------- Validates all your entry on browser side, using javascript you can do that, so before you call your php parser, all required fields must be complete
Would you mind checking what I did wrong on: http://www.davesolution.com/xYzAbJ/input_data_mhs.php Perhaps you can input some data and see the result. I already make revision to this: // default to no error message $message = ''; if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else { $nim = $_POST['nim']; print $_POST['nim']; }
hmmm, I see no errors on the codes you provided may be somewhere, can you send me the codes that parse your data so I could help you. Thanks,
Do you mean input_data.php? input_data.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include ("server.php"); include ("menu.php"); // kata yang di ucwords() akan mempunyai huruf pertamanya // huruf kapital // walaupun sengaja di tulis dalam huruf kecil //$nama = ucwords($nama); $koneksi = mysql_connect ($host, $user, $pass) or die (mysql_error()); mysql_select_db($db) or die (mysql_error()); // default to no error message $message = ''; if (!$_POST['nim']) $message .= 'Required parameter nim is missing.<br />'; else {$nim = $_POST['nim']; print $_POST['nim'];} if (!$_POST['nama']) $message .= 'Required parameter nama is missing.<br />'; else {$nama = $_POST['nama']; print $_POST['nama'];} if (!$_POST['jk']) $message .= 'Required parameter jk is missing.<br />'; else {$jk = $_POST['jk']; print $_POST['jk'];} if (!$_POST['jurusan']) $message .= 'Required parameter jurusan is missing.<br />'; else {$jurusan = $_POST['jurusan']; print $_POST['jurusan'];} if (!$_FILES['foto']) $message .= 'Required parameter foto is missing.<br />'; else {$foto = $_FILES['foto']; print $_FILES['foto'];} //etc. for each parameter if ($message) // we have an error, so display it { echo $message; // do whatever // and redisplay the form include ("input_data_mhs_form.php"); }else // no errors, so process the data { // Copy file ke dalam folder ../image move_uploaded_file( $_FILES['foto']['tmp_name'], '../image/' . $_FILES['foto']['name'] ) //print $_POST['nim']; //print $_POST['nama']; //print $_POST['jk']; //print $_POST['jurusan']; //print $_FILES['foto']; //echo $nim; //echo $nama; //echo $jk; //echo $jurusan; //echo $foto; // Karena hanya memasukkan informasi mahasiswa maka // untuk pengisian nilai dan grade di buatkan form tersendiri // sehingga pada file ini dikosongi mysql_query ("INSERT into mhs (`nim`, `nama`, `jk`, `jurusan`, `foto`) VALUES (`$nim`, `$nama`, `$jk`, `$jurusan`, `$foto`)", $koneksi) or die (mysql_error()); } ?> PHP: input_data_mhs.php will shows you the following form: http://www.davesolution.com/xYzAbJ/input_data_mhs.php I don't think I have another code besides include ("input_data_mhs_form.php"); which included in ----> input_data.php. Basically what it does is re-showing you the form incase the code captures errors. input_data_mhs_form.php <?php error_reporting(E_ALL); ini_set('display_errors', '1'); include ("server.php"); echo " <h1 align=\"center\">Input Data Mahasiswa</h1> <form method=\"post\" action=\"input_data.php\" ENCTYPE=\"MULTIPART/FORM-DATA\"> <table border=\"0\" align=\"center\"> <tr> <td>Nim</td> <td><input type=\"text\" name=\"nim\"></td> </tr> <tr> <td>Nama</td> <td><input type=\"text\" name=\"nama\"></td> </tr>"; echo " <tr> <td>Jenis Kelamin</td> <td><input type=\"radio\" name=\"jk\" value\"1\">Laki</td> </tr> <tr> <td></td> <td><input type=\"radio\" name=\"jk\" value=\"0\">Perempuan</td> </tr>"; echo " <tr> <td>Angkatan</td> <td><select name=\"angkatan\"> <option value=\"kosong\"> Tahun </option>"; $tahun = (integer) date ("Y"); for ($i = $tahun; $i>($tahun - 6); $i--) { echo "<option value=\"$i\">$i"; } echo "</option> </select><td></tr>"; echo " <tr> <td>Jurusan</td> <td><select name=\"jurusan\"> <option value=\"kosong\">---Program Studi--- </option>"; $koneksi = mysql_connect($host, $user, $pass) or die (mysql_error()); mysql_select_db($db, $koneksi) or die (mysql_error()); $query = mysql_query("select * from jurusan order by kode_jurusan", $koneksi) or die (mysql_error()); while ($row_nim = mysql_fetch_array($query)) { echo "<option value = \"$row_nim[0]\" > $row_nim[1] </option>"; } echo "</td>"; echo " <tr> <td>Foto</td> <td><input type=\"FILE\" accept=image/jpeg name=\"foto\"></td></tr>"; echo " <tr> <td><input type=\"submit\" value=\"submit\"></td> <td><input type=\"reset\" value=\"reset\"></td> </tr> </table> "; ?> PHP: To summarize, the main form is: 1) input_data_mhs.php (I posted on the first post) And the second form that captures the data: 2) input_data.php (I posted above)
And my sql codes that creates the table in phpmyadmin is: CREATE TABLE `mhs` ( `nim` char(10) NOT NULL default ' ', `nama` char(25) NOT NULL default ' ', `jk` enum('1','0') NOT NULL default '0', `nilai` int(3) NOT NULL default '0', `grade` char(1) NOT NULL default ' ', `jurusan` char(3) NOT NULL default ' ', `foto` char(15) default NULL, PRIMARY KEY (`nim`) ) TYPE=MyISAM;
I wonder what I should do next. How to test if the data has been captured? Since I see no result in (output table): http://www.davesolution.com/xYzAbJ/daftar_mhs.php