下面给出的代码工作完美。 Db表也插入了值。 但是Echo Message没有在输出中显示
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'admin');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST["register"]))
{
$id = $_POST["id"];
$name = $_POST["user_name"];
$password = $_POST["password"];
$query = mysqli_query($db, "INSERT INTO user (id, user_name, password)VALUES ('$id', '$name', '$password')");
$result = mysqli_query($query);
if($result)
{
echo "Thank You! you are now registered.";
}
}
&GT;
答案 0 :(得分:1)
您以错误的方式拨打了mysqli_query
2次和第二次,只需要拨打一次
// Change
$query = mysqli_query($db, "INSERT INTO user (id, user_name, password)VALUES ('$id', '$name', '$password')");
$result = mysqli_query($query);
// To
$result = mysqli_query($db, "INSERT INTO user (id, user_name, password) VALUES ('$id', '$name', '$password')");
// And change your condition to
if( mysqli_affected_rows($db) ){
..
}
答案 1 :(得分:0)
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'admin');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST["register"]))
{
$id = $_POST["id"];
$name = $_POST["user_name"];
$password = $_POST["password"];
$result = mysqli_query($db, "INSERT INTO user (id, user_name, password)VALUES ('$id', '$name', '$password')");
if($result)
{
echo "Thank You! you are now registered.";
}
}
答案 2 :(得分:0)
本规范正确运作
bytes
答案 3 :(得分:0)
一旦插入记录就正常工作然后打印
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', '');
define('DB_DATABASE', 'test');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE) or die("Error") ;
if(isset($_POST["register"]))
{
$id = $_POST["id"];
$name = $_POST["unm"];
$password = $_POST["pass"];
$query = mysqli_query($db,"INSERT INTO user (id,user_name,password)VALUES ('$id','$name','$password')");
if($query)
{
echo "Thank You! you are now registered.";
}
}
答案 4 :(得分:-1)
<?php
define('DB_SERVER', 'localhost');
define('DB_USERNAME', 'root');
define('DB_PASSWORD', 'hrhk');
define('DB_DATABASE', 'test');
$db = mysqli_connect(DB_SERVER,DB_USERNAME,DB_PASSWORD,DB_DATABASE);
if(isset($_POST["register"]))
{
$id = $_POST["id"];
$name = $_POST["user_name"];
$password = $_POST["password"];
$result = mysqli_query($db, "INSERT INTO user (id, user_name, password) VALUES ('$id', '$name', '$password')");
if($result)
{
echo "Thank You! you are now registered.";
}
}