<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的问题吗?
答案 0 :(得分:1)
您的表单中缺少php标记,而提交按钮中缺少type=submit
。另外,检查manual是否使用php
<html>
<body>
<h1>NewsLetter Registration Time! </h1>
<form action='<?php $_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" name="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>