我有一个简单的问题,我希望我终于可以做到了..我已经创建了一个数据库(" our_new_database"),我在XAMPP中检查过,一切都很好,我也创建了凭据,工作连接,HTML表单和表格。
现在我必须将表单中的信息(名字,名字,电子邮件)插入到表格中,但首先我必须设置3个带有NULL值的变量,并在此之后使用{{1将它们包含在IF / ELSE语句中}}
关键是 - 用户正在向数据库输入信息,然后他的信息将通过$_POST
请求并插入到表中。这是我自己不能继续前进的地方,如果你帮助我会非常高兴。
这是HTML表单:
$_POST
这是凭据+数据库连接+创建表:
<form action="" method="post">
<p>
<label for="userNameOne">User First Name:</label>
<input type="text" name="userOne" id="userNameOne">
</p>
<p>
<label for="userNameTwo">User Second Name:</label>
<input type="text" name="userTwo" id="userNameTwo">
</p>
<p>
<label for="userEmail">Email Address:</label>
<input type="email" name="userEmail" id="user_Email">
</p>
<input type="submit" value="submit" name="submit">
正如我所说,我需要设置这些NULL变量,以及如何将它们放在IF / ELSE语句中,从表单中获取<?php
session_start();
$host = "localhost";
$user_name = "root";
$user_password = "";
$dbname = "our_new_database";
function db_connect($host, $user_name, $user_password, $dbname) {
$connection = mysqli_connect($host, $user_name, $user_password, $dbname);
if(mysqli_connect_errno()){
die("Connection failed: ".mysqli_connect_error());
}
mysqli_set_charset($connection, "utf8");
return $connection;
}
include "app".DIRECTORY_SEPARATOR."config.php";
include "app".DIRECTORY_SEPARATOR."db-connection.php";
include "app".DIRECTORY_SEPARATOR."form.php";
$foo_connection = db_connect($host, $user_name, $user_password, $dbname);
$sql = "CREATE TABLE user_info(
user_name_one VARCHAR(30) NOT NULL,
user_name_two VARCHAR(30) NOT NULL,
user_email VARCHAR(70) NOT NULL UNIQUE
)";
if(mysqli_query($foo_connection, $sql)){
echo "Table created successfully";
}
else {
echo "Error creating table - table already exist.".mysqli_connect_error($foo_connection);
}
$foo_connection->close();
请求并将其插入表中?
答案 0 :(得分:0)
您可以检查用户是否提交了以下表单:
var myString = "bluebells";
// Attempting to assign a value to a string's .length property has no observable effect.
myString.length = 4;
console.log(myString);
/* "bluebells" */