Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/91.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将$variable发布到PHP xampp数据库?_Php_Html_Database_Action - Fatal编程技术网

将$variable发布到PHP xampp数据库?

将$variable发布到PHP xampp数据库?,php,html,database,action,Php,Html,Database,Action,我使用表单操作创建了php提交按钮,目的是通过单击OK按钮,将用户名和学校名称存储在使用xampp的数据库中。我已将数据库表设置为将ID的flds作为主键,将AI、用户名和学校设置为varchar,最大长度为50。我使用的代码显示$con到DB,但只有ID被发送到DB??(我遗漏了什么或需要做什么才能将输入的数据像ID一样存储) 在插入变量之前,需要将post数据加载到变量中。您所做的唯一分配是$username='' 数据库中的$username和$school是空的还是```?是的,这是因为

我使用表单操作创建了php提交按钮,目的是通过单击OK按钮,将用户名和学校名称存储在使用xampp的数据库中。我已将数据库表设置为将ID的flds作为主键,将AI、用户名和学校设置为varchar,最大长度为50。我使用的代码显示$con到DB,但只有ID被发送到DB??(我遗漏了什么或需要做什么才能将输入的数据像ID一样存储)


在插入变量之前,需要将post数据加载到变量中。您所做的唯一分配是$username=''


数据库中的
$username
$school
是空的还是```?是的,这是因为我没有将变量加载到post数据中,它们是空的..谢谢Swarming:您对参数化预处理语句持开放态度,应该使用参数化预处理语句,而不是手动生成查询。它们由或提供。永远不要相信任何形式的输入!即使您的查询仅由受信任的用户执行。谢谢,我知道这是很明显的事情,但我看不见树林里的树木。非常感谢
<?php

require 'config.php';

$username = " "; //$username
$school = " ";//what school they attend

if(isset($_POST['register_button'])){
  $_SESSION['reg_username'] = $username; //Stores first name into session variable

  $_SESSION['reg_school'] = $school; //Stores first name into session variable

  $query = mysqli_query($con, "INSERT INTO users VALUES ('', '$username', '$school')");

 }
?>

<html>
 <head>
  <title> School </title>
</head>
<body>
    <h1> Welcome! </h1>

  <form action="index.php" method="POST">
    <input type="text" name="reg_username" placeholder="Name" value="<?php
        if(isset($_SESSION['reg_username'])) {
            echo $_SESSION['reg_username'];
        }
        ?>" required>

    <br>

        <input type="text" name="reg_school" placeholder="School" value="<?php
        if(isset($_SESSION['reg_school'])) {
            echo $_SESSION['reg_school'];
        }
        ?>" required>

    <br>

        <input type="submit" name="register_button" value="Okay">
</body>
</html>
$username = $_POST['reg_username'];
$school = $_POST['reg_school'];