在PHP中使用多个表单时,不会将插入值输入数据库

在PHP中使用多个表单时,不会将插入值输入数据库,php,mysql,Php,Mysql,signup.php <?php if (isset($_POST['signup'])) { $con = mysqli_connect("localhost", "root", ""); mysqli_query($con, "CREATE DATABASE dream"); mysqli_select_db($con, "dream"); $counter = 1; $uname = $_POST['uname']; $uem

signup.php

   <?php
  if (isset($_POST['signup'])) {
    $con = mysqli_connect("localhost", "root", "");
    mysqli_query($con, "CREATE DATABASE dream");
    mysqli_select_db($con, "dream");
    $counter = 1;
    $uname = $_POST['uname'];
    $uemail = $_POST['uemail'];
    $upass = $_POST['upass'];
    $gender = $_POST['gender'];
    $uage = $_POST['uage'];
    $ucourse = $_POST['ucourse'];
    $uclass = $_POST['uclass'];
    $ucontact = $_POST['ucontact'];
    $uaddress = $_POST['uaddress'];

    $ct = "CREATE TABLE student(sno INTEGER(3) NOT NULL AUTO_INCREMENT PRIMARY KEY, name VARCHAR(20), email VARCHAR(30), password VARCHAR(30), gender VARCHAR(30), age INTEGER(3), course VARCHAR(30), class VARCHAR(30), contact INTEGER(3), 
        address VARCHAR(100) )";
    mysqli_query($con, $ct);
    mysqli_query($con, "INSERT INTO student VALUES('$counter', '$uname','$uemail','$upass','$gender',
        '$uage','$ucourse','$uclass','$ucontact','$uaddress')");
    }

    ?>

<html>
<head></head>
<body>
    <form method = "post" action = "signup2.php"> 
    <div class = "container">

        <h2>Sign Up for Dream Media</h2>
        <table width = "550"  bordercolor = "#ffcc99" align = "center" bgcolor = "#cce5ff" cellpadding="12" border-radius = "5">
            <tr>
                <th>Name</th>
                <td><input type = "text" placeholder = "Enter your name" name = "uname" size = "30"></td>
            </tr>
            <tr>
                <th>Email</th>
                <td><input type = "email" placeholder = "Enter your email" name = "uemail"  size = "30"></td>
            </tr>
            <tr>
                <th>Password</th>
                <td><input type = "password" placeholder = "Enter your password" name = "upass"  size = "30"></td>
            </tr>
            <tr>
                <th>Gender</th>
                <td><input type = "radio"  name = "gender" value = "male">Male
                    <input type = "radio"  name = "gender" value = "female">Female</td>
            </tr>
            <tr>
                <th>Age</th>
                <td><input type = "text" placeholder = "Enter your Age" name = "uage"  size = "30"></td>
            </tr>
            <tr>
                <td colspan = "2" class="right"><input type = "submit" Value = "Next"></td>
            </tr>
        </table>
    </div>
    </form>
    <footer>

  <p>Contact information: <a href="mailto:someone@example.com">dreamsmedia@dms.com</a>.</p>
</footer>

</body>
</html>

注册梦想媒体
课程
PHP
网页设计
Java脚本
Photoshop
上课时间
接触
地址
final.php

    <?php
session_start();
$counter = 1;
$_SESSION['uname'] = $_POST['uname'];
$_SESSION['uemail'] = $_POST['uemail'];
$_SESSION['upass'] = $_POST['upass'];
$_SESSION['gender'] = $_POST['gender'];
$_SESSION['uage'] = $_POST['uage'];
print_r($_POST);
?>
<html>
<head></head>
<body>
    <form method = "post" action = "dreams.php">
    <div class = "container">

        <h2>Sign Up for Dream Media</h2>
        <table width = "550" border = "0" bordercolor = "#ffcc99" align = "center" bgcolor = "#cce5ff" cellpadding="12" border-radius = "5">
            <tr>
                <th>Course</th>
                <td><input type = "checkbox" name  = "ucourse[]" value = "php">PHP
                <input type = "checkbox" name  = "ucourse[]" value = "web">Web Designing
            <input type = "checkbox" name  = "ucourse[]" value = "js">Java Script
        <input type = "checkbox" name  = "ucourse[]" value = "ps">Photoshop
    </td>
            </tr>
            <tr>
                <th>Class Timinings</th>
                <td><input type = "text" placeholder = "Class timings" name = "uclass" size = "30"></td>
            </tr>
            <tr>
                <th>Contact</th>
                <td><input type = "text" placeholder = "1234567890" name = "ucontact" size = "30"></td>
            </tr>
            <tr>
                <th>Address</th>
                <td><textarea name = "uaddress" rows = "5" cols = "47" ></textarea></td>
            </tr>
            <tr>
                <td colspan = "2" class = "right"><input type = "submit" Value = "Finish" name = "signup"></td>
            </tr>
        </table>
    </div>
    </form>


</body>
</html>
 <?php
    session_start();


    $_SESSION['ucourse'] = $_POST['ucourse'];
    $_SESSION['uclass'] = $_POST['uclass'];
    $_SESSION['ucontact'] = $_POST['ucontact'];
    $_SESSION['uaddress'] = $_POST['uaddress'];

    print_r($_POST);
    ?>

这里我使用了两种形式,
1.signup.php
2.signup2.php


使用从表单1到表单2检索数据的会话输入数据,输入的值不会插入到数据库中。

您的最终插入查询是否在final.php中? 我认为你在signup2.php中的行为将带你进入dreams.php,而不是final.php 改变这个

<form method = "post" action = "dreams.php">

请修改查询以适合您的表结构

$\u POST['ucourse']
应该是一个数组,您不能连接它,您必须先将其内爆。您已更改但未插入数据库php是否会引发任何错误?您是否每次都运行
创建表学生
?或者你只是为了让我们理解表的结构而展示它吗?当我创建表单时,我将与createtable studentsis一起提交所有final.php代码?因为我看不到任何要插入数据库的查询。让我看看您所有的final.php代码您的final.php代码不包含任何sql插入查询dude。所以这些值不会被插入到DB中。见我编辑的帖子
<form method = "post" action = "final.php">
mysqli_query($con, "INSERT INTO your_table VALUES($_SESSION['ucourse'], $_SESSION['uclass'],$_SESSION['ucontact'],$_SESSION['uaddress']");