当注册成功时,PHP HTML提示框 [英] PHP HTML alert box when the registration is successful

查看:303
本文介绍了当注册成功时,PHP HTML提示框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在html中有一个注册表单和一个连接到数据库的php代码。现在,如果注册成功并添加到数据库中,如何通过弹出框提醒用户它已成功?



html代码仅仅是一个简单的表单代码,所以继承了php代码:

  
if(isset($ _ POST ['submit'])){
$ fname = $ _POST ['firstname'];
$ lname = $ _POST ['lastname'];
$ mname = $ _POST ['middlename'];
$ birthday = $ _POST ['year']。 '/'。 $ _POST ['month']。 '/'。 $ _ POST [天];
$ sex = $ _POST ['sex'];
$ age = $ _POST ['age'];
$ address = $ _POST ['address'];
$ telephone = $ _POST ['telephone'];
$职业= $ _POST ['职业'];
$ telephone = $ _POST ['telephone'];
$ cfname = $ _POST ['contactfirstname'];
$ clname = $ _POST ['contactlastname'];
mysql_connect('localhost','root','');
mysql_select_db('HMIS');

$ query =INSERT INTO`patientrecords` VALUES('','$ lname','$ fname','$ mname','$ birthday','$ sex','$ address , '$电话', '$职业', '$列表CLNAME', '$ cfname');

if(mysql_query($ query)){
echoRegistered;
} else {
echoError!。 mysql_error();
}
}

?>

只有当某个按钮被点击时,我才可以执行javascript警报框。但在PHP代码中,你不需要一个按钮..所以..你是怎么做到的? 解决方案

试试这个吧应该工作

  if(成功)
{
echo< script type = \text / javascript\ > 中。
alert('success');。
< / script>;
}


I have a registration form in html and a php code that connects to the database. Now if the registration is successful and is added to the database, how to i alert the user that it is successful with a popup box?

the html code is just a simple form codes so heres the php code:

<?php

if(isset($_POST['submit'])){
    $fname = $_POST['firstname'];
    $lname = $_POST['lastname'];
    $mname = $_POST['middlename'];
    $birthday = $_POST['year'] . '/' . $_POST['month'] . '/' . $_POST['day'];
    $sex = $_POST['sex'];
    $age = $_POST['age'];
    $address = $_POST['address'];
    $telephone = $_POST['telephone'];
    $occupation = $_POST['occupation'];
    $telephone = $_POST['telephone'];
    $cfname = $_POST['contactfirstname'];
    $clname = $_POST['contactlastname'];
    mysql_connect('localhost', 'root', '');
    mysql_select_db('HMIS');

    $query = "INSERT INTO `patientrecords` VALUES('','$lname','$fname','$mname','$birthday','$sex','$address','$telephone','$occupation','$clname','$cfname')";

    if(mysql_query($query)){
        echo "Registered";
    }else{
        echo "Error!". mysql_error();
    }
}

?>

I can do the javascript alert box only when a certain button is clicked. But in the php code you dont need a button.. so.. how do you do it?

解决方案

Try this, it should work

if(success)
{
   echo "<script type=\"text/javascript\">".
        "alert('success');".
        "</script>";
}

这篇关于当注册成功时,PHP HTML提示框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆