dtczp02204 2013-07-31 06:54
浏览 64

从PHP中的函数获取值并在div或列中显示值,使用以前的值重新加载页面

I am having two fields 'name' and 'username'. I am checking the username availability and this I am able to check. My problem is with the manner in which I display the form. I want to achieve

  1. Showing messages in the same row in which the username is displayed but in the third column.
  2. While showing the messages, it should display the previous entered values.

And I want to achieve this just with html, javascript and php. I don't want to go for any other language or technology

Login.php is building the form.

    <?php 
include 'login2.php';
function form($name, $username)
{
?>
<form name="mylogin" method="post">
<table>
<tr><td>Name</td>
<td><input type="text" id="name" name="name" value="<?php echo $name?>" required></td></tr>
<tr><td>Username</td>
<td><input type="text" id="user" name="user" value="<?php echo $username?>" required></td>
<td id="messgae"></td>//want to display message over here have tried value"<?php echo $message"?>                  
</tr>
<tr><td><input type="submit" name="submit" value="Username Availability Check"></td></tr>
<?php usercheck()?>
</table>
</form>
<?php
}
?>

<?php
form('','')
?>

In Login2.php I am just checking the username and right now I am not inserting the values, so that the insert query is commented and for sending back the entered values by user. The problem I am facing is, the form is getting displayed twice after I click submit button or user availability check button. I know it is happening because I am calling the function twice but how to avoid it?

Code

<?php 
function connect()
{
    mysql_connect('localhost','root','password');
    mysql_select_db('loginprac');
}
function usercheck()
    {
        if(isset($_POST['submit']))
        {
        connect();
        $name=$_POST['name'];
        $user = mysql_real_escape_string($_POST['user']);
        $check_for_username = mysql_query("SELECT user from userpage WHERE user = '$user'");
        $count = mysql_num_rows($check_for_username);
        if($count != 0)
        {

            form($name,$user);
        }
        }
    }
    /*function insert()
{
    connect();
    if(isset($_POST['submit']))
    {
        usercheck();
        $name=$_POST['name'];
        $user=$_POST['user'];
        $sql1= "INSERT INTO userpage (name,user) VALUES ('$name','$user')";
        mysql_query($sql1);
    }

}*/
?>
  • 写回答

2条回答 默认 最新

  • doutan8506 2013-07-31 07:22
    关注

    Get the <form> outside the function form(). Pass only the messages and username to the function.

    评论

报告相同问题?

悬赏问题

  • ¥15 求帮我调试一下freefem代码
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图