我正在尝试制作一个简单的代码,该代码将根据用户电子邮件从数据库中获取特定数据。
例如,用户将在文本字段中输入他的电子邮件,然后按提取按钮以获取自己的信息。我制作了这段代码,但它不起作用:
enter your email: <input type = "text" name = "email" size="30"/>
<input type = "submit" name = "fetch" size="30" value="fetch" />
<?php
mysql_connect("localhost","name","pass");
mysql_select_db("table_Name");
if(isset($_POST['fetch']))
{
$email = $_POST['email'];
$query = "SELECT * FROM table_Name WHERE user_email = '$email'";
$run = mysql_query($query );
if (mysql_num_rows($run) > 0)
{
$_SESSION['email']= $email;
echo 'your information'.$email;
}
else
{
echo "<script>alert('wrong email!')</script>";
}
}
?>
答案 0 :(得分:0)
您需要在文件中添加表单。像这样:
<form method="post" action="#">
<input type = "text" name = "email" size="30"/>
<input type = "submit" name = "fetch" size="30" value="fetch" />
</form>
我建议至少添加此内容以验证电子邮件输入:
$email = $_POST["email"];
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {die()};