通过从另一页传递的ID将值插入数据库中的两个不同表中

时间:2019-06-01 10:09:36

标签: php html mysql

我已将ID从一页传递到另一页,我想通过在数据库中使用这些ID将值插入到两个不同的表中。

我尝试了$_GET['id']并在insert语句中使用where条件,但是值未正确插入。

Page1.php

<?php

require('db.php');
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <title>GlobalWorkOnline Home</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
  <link rel="stylesheet" href="css/style.css"/>
  <link href="css1/style.css" rel='stylesheet' type='text/css' />
</head>
<body>

<?php include("includes/header1.php") ?>

<section>
  <div class="container-fluid">
    <div class="row">
      <div class="col-lg-6 login1">
        <div class="flex-container">
          <a href="registration.php?viewregistrationid=1"><div class="col-lg-12">
            <h1 class="text-center">Freelance</h1>
            <h5 class="text-center">Registration</h5>
          </div></a>
        </div>
      </div>
      <div class="col-lg-6 login2">
        <div class="flex-container">
          <a href="registration.php?viewregistrationid=2"><div class="col-lg-12">
            <h1 class="text-center">Employer</h1>
            <h5 class="text-center">Registration</h5>
          </div></a>
        </div>
      </div>
    </div>
  </div>
</section>

</body>
</html>

Page2.php

<!DOCTYPEhtml>
<html>
<head>
<meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
  <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
  <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
<title>GlobalWorkOnline Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
    require('db.php');
    // If form submitted, insert values into the database.

    if (isset($_REQUEST['submit'])){
        $username = stripslashes($_REQUEST['username']); // removes backslashes
        $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
        $name = stripslashes($_REQUEST['name']);
        $name = mysqli_real_escape_string($con,$name);
        $password = stripslashes($_REQUEST['password']);
        $password = mysqli_real_escape_string($con,$password);

        $trn_date = date("Y-m-d H:i:s");
        $query = "INSERT into `freelancer_details` (username, password, fullname, trn_date) VALUES ('$username', '".md5($password)."', '$name', '$trn_date') WHERE 1='".$_GET['viewregistrationid']."'";
        $result = mysqli_query($con,$query);
        if($result){
            echo "<div class='form text-center'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
        }
    }


    if (isset($_REQUEST['submit'])){
        # code...
        $username = stripslashes($_REQUEST['username']); // removes backslashes
        $username = mysqli_real_escape_string($con,$username); //escapes special characters in a string
        $name = stripslashes($_REQUEST['name']);
        $name = mysqli_real_escape_string($con,$name);
        $password = stripslashes($_REQUEST['password']);
        $password = mysqli_real_escape_string($con,$password);

        $trn_date = date("Y-m-d H:i:s");
        $query = "INSERT into `employer_details` (username, password, fullname, trn_date) VALUES ('$username', '".md5($password)."', '$name', '$trn_date') WHERE 2='".$_GET['viewregistrationid']."'";
        $result = mysqli_query($con,$query);
        if($result){
            echo "<div class='form text-center'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
    }
}

    else{
?>
<div class="container">
<h1 class="text-center head">GlobalWorkOnline Registration Form</h1>
<div class="col-sm-offset-3 col-sm-6 rform">
<form class="form-horizontal" name="registration" action="" method="post">

    <div class="form-group content">
        <label class="control-label col-sm-3" for="name">Full Name :</label>
        <div class="col-sm-offset-0 col-sm-9">
        <input type="text" class="form-control" name="name" placeholder="Full Name" required>   
        </div>
    </div>
    <div class="form-group content">
        <label class="control-label col-sm-3" for="uname">Username :</label>
        <div class="col-sm-offset-0 col-sm-9">
        <input type="text" class="form-control" name="username" placeholder="Enter Username" required>  
        </div>
    </div>
    <div class="form-group content">
        <label class="control-label col-sm-3" for="pwd">Password :</label>
        <div class="col-sm-offset-0 col-sm-9">
        <input type="password" class="form-control" name="password" placeholder="Enter Password" required>  
        </div>
    </div>
    <div class="form-group">        
      <div class="col-sm-offset-3 col-sm-10">
        <input class="buttonregister" type="submit" class="register" name="submit" value="Register" />
      </div>
    </div>

</form>
</div>
</div>
<?php } ?>

</body>
</html>

应将值插入数据库中的各个表中,但不要将任何内容插入任何表中。页面空白。

0 个答案:

没有答案