将数据插入2个表mysql php

时间:2017-12-08 14:51:37

标签: php mysql mysqli phpmyadmin

我有两张桌子,预订和用户。我希望当用户填写表单时,列用户名和密码也会插入到用户表中。我对预订表的查询是有效的,但不在用户表中。

Php代码:

import java.util.Scanner;

public class Bitrex {
    public static void main(String[] args) {
        Scanner Bitcoin = new Scanner (System.in);
        double num1;
        double num2=0.9975;
        double answer;

        System.out.println("Enter Expected Price: ");
        num1 = Bitcoin.nextDouble();
        answer = num1 * num2;
        System.out.println(answer);
    } // end of main
}

1 个答案:

答案 0 :(得分:0)

您应该在重定向到下一页之前验证数据的提交 我正在尝试你的代码,所以我创建了两个表: 用户{id,用户名,密码,电子邮件} 本地{id,label,description} 它适用于我

<?php


$host = "localhost";

$user = "root";

$password = "";

$database = "dbtestsub";

$conn = new mysqli($host, $user, $password, $database);

if ($conn->connect_errno) {

    echo "Failed to connect to MySQL: " . $mysqli->connect_error;

}
/*
$sql="INSERT INTO reservation 
VALUES (null,
'".$_POST['type']."',
'".$_POST['title']."',
'".$_POST['fname']."',
'".$_POST['lname']."',
'".$_POST['contact']."',
'".$_POST['username']."'
,'".$_POST['password']."',
'".$_POST['email']."',
'".$_POST['address']."',
'".$_POST['checkin']."',
'".$_POST['checkout']."');"; */
/*

$sql .= "INSERT INTO users 
VALUES (null,'".$_POST['username']."','".$_POST['password']."','client');"; */

$sql = "INSERT INTO user 
    VALUES (null,'" . new_user . "','" . yeah_bro . "','" . useremail . "');";

$sql .= "INSERT INTO local 
    VALUES (null,'" . local1 . "','" . descp1 . "');";

mysqli_multi_query($conn, $sql);

mysqli_close($conn);

//      header("Location: login.php");

所以告诉我是否有任何错误来检查