我制作通常的注册表格,但收到错误**'
SQLSTATE [HY093]:参数号无效:参数未定义
之后,我运行查询
var_dump($this->conn->errorInfo());
,结果是**
array(3) { [0]=> string(5) "00000" [1]=> NULL [2]=> NULL }
这是我在class.user.php文件中的代码:
public function register
($nama,$noktp,$alamat,$kota,$jeniskelamin,$tempatlahir,$tanggallahir,$nomorhp,
$email,$namainstansi,$pimpinaninstansi,$kotainstansi,$jnsinstansi,$nomortelepon,$emailinstansi)
{
$this->conn->beginTransaction();
try
{
$stmt = $this->conn->prepare("INSERT INTO user (name,user_email)
VALUES(:nama,:user_email)");
$stmt->bindparam(':name', $nama,PDO::PARAM_STR);
$stmt->bindparam(':user_email', $email, PDO::PARAM_STR);
$stmt->execute();
$lastInsertID = $this->conn->lastInsertId();
$stmt = $this->conn->prepare("INSERT INTO data_user
(id_pengguna,no_ktp,alamat,kota,jenis_kelamin,tempat_lahir,tanggal_lahir,nomor_hp)
VALUES(:idpengguna,:noktp,:alamat,:kota,:jk,:tempatlahir,:tanggallahir,:nomorhp)");
$stmt->bindparam(':idpengguna', $lastInsertID,PDO::PARAM_STR);
$stmt->bindparam(':noktp', $noktp, PDO::PARAM_STR);
$stmt->bindparam(':alamat', $alamat, PDO::PARAM_STR);
$stmt->bindparam(':kota', $kota, PDO::PARAM_STR);
$stmt->bindparam(':jk', $jeniskelamin, PDO::PARAM_STR);
$stmt->bindparam(':tempatlahir', $tempatlahir, PDO::PARAM_STR);
$stmt->bindparam(':tanggallahir', $tanggallahir, PDO::PARAM_STR);
$stmt->bindparam(':nomorhp', $nomorhp, PDO::PARAM_STR);
$stmt->execute();
$stmt = $this->conn->prepare("INSERT INTO data_instansi
(id_pengguna,nama_instansi,pimpinan,kota,jenis_instansi,nomor_telepon,email_instansi)
VALUES(:idpengguna,:namainstansi,:pimpinan,:kota,:jenisinstansi,:nomortelepon,:emailinstansi)");
$stmt->bindparam(':idpengguna', $lastInsertID,PDO::PARAM_STR);
$stmt->bindparam(':namainstansi', $namainstansi, PDO::PARAM_STR);
$stmt->bindparam(':pimpinan', $pimpinaninstansi, PDO::PARAM_STR);
$stmt->bindparam(':kota', $kotainstansi, PDO::PARAM_STR);
$stmt->bindparam(':jenisinstansi', $jnsinstansi, PDO::PARAM_STR);
$stmt->bindparam(':nomortelepon', $nomortelepon, PDO::PARAM_STR);
$stmt->bindparam(':emailinstansi', $emailinstansi, PDO::PARAM_STR);
$stmt->execute();
$this->conn->commit();
}
catch(PDOException $e)
{
$this->conn->rollBack();
echo $e->getMessage();
var_dump($this->conn->errorInfo());
}
}
register.php上的代码:
if(isset($_POST['submit'])){
$nama = $_POST['nama'];
$noktp = $_POST['ktp'];
$alamat = $_POST['alamat'];
$kota = $_POST['kota'];
$jk = $_POST['jk'];
$tempatlahir = $_POST['tempat'];
$tanggallahir = $_POST['tgl'];
$nomorhp = $_POST['hp'];
$email = $_POST['email'];
$namainstansi = $_POST['namains'];
$pimpinanins = $_POST['pimins'];
$kotains = $_POST['kotains'];
$jenisins = $_POST['jins'];
$nomortlp = $_POST['notel'];
$emailins = $_POST['emailins'];
try{
$user_register->register($nama,$noktp,$alamat,$kota,$jk,$tempatlahir,$tanggallahir,
$nomorhp,$email,$namainstansi,$pimpinanins,$kotains,$jenisins,$nomortlp,$emailins);
}
catch (PDOException $e){
echo $e->getMessage();
}
}
这是表格:
<form id="msform" action="registrasi.php" method="post" enctype="multipart/form-data">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Identitas Pengguna</li>
<li>Identitas Instansi</li>
<li>Dokumen Pendukung</li>
<li>Konfirmasi Hasil</li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title">Identitas Pengguna</h2>
<h3 class="fs-subtitle">Lengkapi Identitas Pribadi Anda</h3>
<table border="0">
<tr style="width: 100%">
<td class="judul-tabel">Nama</td>
<td style="width: 800px"><input name="nama" placeholder="Masukkan Nama" required></td>
</tr>
<tr>
<td class="judul-tabel">No KTP</td>
<td><input type="text" maxlength="17" name="ktp" placeholder="Masukkan Nomor KTP" required></td>
</tr>
<tr>
<td class="judul-tabel" style="vertical-align: middle">Alamat</td>
<td><textarea name="alamat" placeholder="Masukkan Alamat" required></textarea></td>
</tr>
<tr>
<td class="judul-tabel">Kota</td>
<td><input type="text" name="kota" placeholder="Masukkan Kota" required></td>
</tr>
<tr>
<td class="judul-tabel">Jenis Kelamin</td>
<td class="isi-tabel">
<input type="radio" name="jk" value="Laki-laki"
style="width: 20px; margin-top: 5px; margin-bottom: 15px;" required>Laki-laki
<input type="radio" name="jk" value="Perempuan"
style="width: 20px; margin-top: 5px; margin-bottom: 15px;" required>Perempuan
</td>
</tr>
<tr>
<td class="judul-tabel">Tempat Lahir</td>
<td><input type="text" name="tempat" placeholder="Masukkan Tempat Lahir" required></td>
</tr>
<tr>
<td class="judul-tabel">Tanggal Lahir</td>
<td><input type="date" name="tgl" required></td>
</tr>
<tr>
<td class="judul-tabel">Nomor Hp</td>
<td><input type="text" maxlength="12" name="hp" placeholder="Masukkan Nomor Hp" required></td>
</tr>
<tr>
<td class="judul-tabel">Email</td>
<td><input type="email" name="email" placeholder="Masukkan Email" required></td>
</tr>
</table>
<input type="button" name="stepone" id="stepone" class="next action-button" value="Selanjutnya" />
</fieldset>
<fieldset>
<h2 class="fs-title">Identitas Instansi</h2>
<h3 class="fs-subtitle">Lanjutkan dengan Pengisian Data Kantor Anda</h3>
<table border="0">
<tr style="width: 100%">
<td class="judul-tabel">Nama Instansi</td>
<td style="width: 900px"><input type="text" name="namains" placeholder="Masukkan Nama Instansi" required></td>
</tr>
<tr>
<td class="judul-tabel">Pimpinan Instansi</td>
<td style="width: 800px"><input type="text" name="pimins" placeholder="Masukkan Nama Pimpinan Instansi" required></td>
</tr>
<tr>
<td class="judul-tabel">Kota Instansi</td>
<td><input type="text" name="kotains" placeholder="Masukkan Kota Instansi" required></td>
</tr>
<tr>
<td class="judul-tabel">Jenis Instansi</td>
<td><input type="text" name="jins" placeholder="Masukkan Jenis Instansi" required></td>
</tr>
<tr>
<td class="judul-tabel">Nomor Telepon</td>
<td><input type="text" maxlength="12" name="notel" placeholder="Masukkan Nomor Telepon Instansi" required></td>
</tr>
<tr>
<td class="judul-tabel">Email Instansi</td>
<td><input type="email" name="emailins" placeholder="Masukkan Email Instansi" required></td>
</tr>
</table>
<input type="button" name="previous" class="previous action-button" value="Sebelumnya" />
<input type="submit" name="submit" value="Daftar">
</fieldset>
<?php
?>
</form>
我检查过参数和变量是否合适,参数是15,变量也是如此。但它仍然无效。我的代码出了什么问题,顺便问一下?我希望我能在这里找到答案,对不起我的英语。