【发布时间】:2016-05-19 20:02:25
【问题描述】:
<html>
<body>
<h1>NewsLetter Registration Time! </h1>
<form action='$_SERVER["PHP_SELF"]' method='post'>
Enter the username to be added:
<input type="text" id="nt1" name="username"/>
Enter the corresponding email-id to be added:
<input type="text" id="nt1" name="email_id"/>
<input type="submit"/>
<?php
if(isset($_POST['submit']))
{
echo "<h1 style='color:red;'> Entering Data..... </h1>";
$database=mysqli_connect('localhost','root','','userdetails')
or die("didn't work");
mysqli_query($database,"INSERT INTO userdetails (username,password)VALUES ($_POST[username],$_POST[email_id])");
mysqli_close($database);
echo "<h3 style='color:red;'> Check the database..... </h3>";
}
?>
</body>
</html>
我无法使用 $_SERVER['PHP_SELF'] 访问数据库,但如果我使用其他一些 php 脚本,代码就可以工作。这是xampp的问题吗?
【问题讨论】:
-
你忘记了你的 PHP 标签
-
@JohnConde 加了php标签还是不行!
-
<form action='$_SERVER["PHP_SELF"]' method='post'>那是因为您不在 PHP 中使用它 - 只需执行action=''。并且if(isset($_POST['submit'])){...}中的所有内容都不会启动。 -
那你也会失败
($_POST[username],$_POST[email_id])