首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用php、mysqli、procedural输入数据时代码会自动更改

使用php、mysqli、procedural输入数据时代码会自动更改
EN

Stack Overflow用户
提问于 2017-05-02 02:28:30
回答 1查看 46关注 0票数 0

我的表名为"pelanggan“

代码语言:javascript
复制
my structure table -> id_pelanggan -> primary key -> auto increment
                      username
                      email
                      alamat
                      telp
                      password

注册页面

代码语言:javascript
复制
<?php require_once "core/init.php";

$error='';

if( isset($_POST['submit']) ){
  $nama   = $_POST['username'];
  $email  = $_POST['email'];
  $alamat = $_POST['alamat'];
  $telp   = $_POST['telp'];
  $pass   = $_POST['password'];


if(!empty(trim($nama)) && !empty(trim($email)) && !empty(trim($alamat)) && !empty(trim($telp)) && !empty(trim($pass)) ){



  if(register_cek_nama($nama) ){
    //memasukan database
          if(register_user($nama, $email, $alamat, $telp, $pass)) {
            $error= 'berhasil daftar register';
          }else{
            $error= 'gagal register';}
      }else{
      $error= ' nama sudah ada, tidak bisa daftar ';}
  }else{
      $error= 'form tidak boleh kosong';
  }
}

?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title></title>

  <!-- Latest compiled and minified css -->
     <link rel="stylesheet" href="view/css/bootstrap.min.css">
  <!-- optional theme-->
     <link rel="stylesheet" href="view/css/bootstrap-theme.min.css">
  <!--my custom css-->
     <link rel="stylesheet" href="view/css/style.css">
  <!--font-awesome-->
     <link rel="stylesheet" href="view/font-awesome/css/font-awesome.min.css">


<!---------------------------------->

<style>

body{

  font-family: arial monospace;
  background-color :#eee;
}

.container{

  display: flex;
  align-items: center;
  justify-content: center;}

.page{

padding:5px;
margin-top: 40px;
margin-bottom: 40px;
height: 510px;
width: 400px;
background: #fff;
}

.content{
  height: 100%;
  padding: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.logo-register h2{
  font-family:Chaparral Pro Light;
font-weight: bold;
}

.logo-register h5{
  font-family: calibri;
  color:#808080;
  border-bottom:1px solid #eee;
  padding-bottom: 5px;

}

.form-group .form-control{
  border-radius: 0;
  border:1px solid #eee;
  padding: 5px;
}

.bawah-submit h5{  font-family: calibri;
                                color:#808080;}

.punya-akun h5{font-family: calibri;
                    color:#808080;}

  #error{color: rgb(212, 19, 65);
                    }









</style>


</head>

<body>


              <div class="container">

                          <div class="page">
                                <div class="content">
                                    <div class="row">
                                        <div class="logo-register">
                                                <h2><a href="index.php">Wherco</a></h2>
                                              <h5>Buat akun untuk melakukan order</h5>
                                        </div>


                                              <?php
                                                  if(isset($_SESSION['msg'])) { ?>
                                                <div id="error">
                                                    <?php echo $_SESSION['msg'];
                                                    unset($_SESSION['msg']); ?>
                                                </div> <br>
                                              <?php }  ?>

                                        <?php if($error != ' '){ ?>
                                            <div id="error">
                                                <?php echo $error; ?>
                                            </div>
                                          <?php } ?>


                                  <form class="form-horizontal" action="register.php" method="post">
                                        <div class="form-group">
                                             <input type="text" class="form-control" style="text-transform:lowercase;"  name="username" placeholder="Nama lengkap" Required autofocus>
                                          </div>

                                          <div class="form-group">
                                               <input type="email" class="form-control"  name="email" placeholder="Alamat email" Required>
                                          </div>

                                          <div class="form-group">
                                              <textarea class="form-control" rows="3"  name="alamat" placeholder="Alamat tinggal" Required autofocus ></textarea>
                                            </div>

                                            <div class="form-group">
                                                 <input type="number" class="form-control"  name="telp" placeholder="Nomer yang bisa di hubungi" Required>
                                            </div>

                                            <div class="form-group">
                                                 <input type="password" style="text-transform:lowercase;"  class="form-control" name="password"   id="exampleInputEmail1" placeholder="Kata sandi untuk akun order" Required>
                                            </div>

                                            <div class="form-group">
                                              <input type="submit" name="submit" class="btn btn-info btn-block" value="Daftar">
                                            </div>


                                            <div class="bawah-submit">
                                                    <h5> Dengan mendaftar anda menyetujui Ketentuan<br>
                                                    dan Kebijakan Privasi kami </h5>
                                          </div>

                                          <div class="punya-akun">
                                            <h5> Punya akun? <a href="login.php">Masuk</a> </h5>
                                          </div>
                                </div>
                          </div>
                      </div>
                    </div

函数寄存器用户

代码语言:javascript
复制
<?php

function register_user($nama, $email, $alamat, $telp, $pass){
global $connect;


//mencegah sql injection
$nama   = mysqli_real_escape_string($connect, $nama);
$email  = mysqli_real_escape_string($connect, $email);
$alamat = mysqli_real_escape_string($connect, $alamat);
$telp   = mysqli_real_escape_string($connect, $telp);
$pass   = mysqli_real_escape_string($connect, $pass);




$pass = password_hash($pass, PASSWORD_DEFAULT);


  $query = "INSERT INTO pelanggan (username, email, alamat, telp, password) VALUES ('$nama', '$email', '$alamat', '$telp', '$pass')";

  if( mysqli_query($connect, $query) ){

        return true;
      }else{
        return false;
  }
}
?>

我的问题是如何使我的表的id号自动更改。例如:当我输入数据时,从id "02“到"customer02”或"p02“。

我希望用户在创建帐户时不知道他们得到了什么代码。我不知道如何声明查询。谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-05-02 02:32:15

只需将其附加到变量的开头即可。

代码语言:javascript
复制
$id = $_POST['id'];
$id = "Customer".$id;
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43724341

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档