首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >字段旁边的同一页验证

字段旁边的同一页验证
EN

Stack Overflow用户
提问于 2016-06-13 20:42:28
回答 1查看 22关注 0票数 0

我试图将我的错误代码放在同一个页面的字段下面,我现在得到的是一个单独的页面打开,上面写着:“你没有填写必填字段。”

下面是我的表单HTML代码:

代码语言:javascript
复制
<!-- Header Code -->

<style type="text/css">
.OBJ-1 { margin:0;background:transparent url('wpimages/wp2ce4b072.png') no-repeat left top; }
.P-1 { text-align:center;line-height:1px;font-family:"Tahoma", sans-serif;font-style:normal;font-weight:700;color:#000000;background-color:transparent;font-variant:normal;font-size:18.0px;vertical-align:0; }
.C-1 { line-height:22.00px;font-family:"Tahoma", sans-serif;font-style:normal;font-weight:700;color:#000000;background-color:transparent;text-decoration:none;font-variant:normal;font-size:18.0px;vertical-align:0; }
.C-2 { line-height:18.00px;font-family:"Georgia", serif;font-style:normal;font-weight:normal;color:#626262;background-color:transparent;text-decoration:none;font-variant:normal;font-size:16.0px;vertical-align:0; }
.OBJ-2 { border:none;border-radius:10px / 10px;background:#ffffff;font-family:Georgia;text-align:left;font-size:18px;color:#000000; }
.OBJ-3 { border:none;border-radius:10px / 10px;background:#626262;font-family:Georgia;text-align:center;font-size:18px;color:#fdfdfd; }
代码语言:javascript
复制
<!-- Form form_14 -->


<form id="form_14"  action="dbtest2.php" method="post" target="_top" enctype="application/x-www-form-urlencoded" class="OBJ-1"  style="position:absolute;left:220px;top:42px;width:335px;height:104px;">

<div  style="position:absolute;left:4px;top:4px;width:327px;height:22px;overflow:hidden;">
    <p class="Body P-1"><span class="C-1">sign up</span></p>
</div>

<label for="">

    <div  style="position:absolute;left:4px;top:30px;width:327px;height:18px;overflow:hidden;">
        <p class="Body"><span class="C-2"><br></span></p>
    </div>

</label>


<!-- Form Edit Box -->


<input name="firstname" class="OBJ-2" maxlength="32" placeholder="firstname" style="position:absolute;left:4px;top:48px;width:327px;height:24px;">



<!-- Form Button -->


<input name="submit" class="OBJ-3" type="submit" value="submit"  style="position:absolute;left:4px;top:76px;width:327px;height:24px;">

这是我的PHP字段验证脚本:

代码语言:javascript
复制
<?php

$firstname = $_POST['firstname'];
if(empty($firstname))
{
echo "You did not fill out the required fields.";
}



$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="correoervhanski"; // Database name
$tbl_name="users"; // Table name

// Connect to server and select database.
mysql_connect("$host", "$username", "$password")or
die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");



?>

如果有人能亲切地告诉我如何放置验证消息的代码出现在下面的字段将非常感谢。

谢谢:)

EN

回答 1

Stack Overflow用户

发布于 2016-06-13 20:45:17

好的,

基本上,您正在尝试在同一个页面上运行PHP脚本-为此,您最好的策略是使用AJAX。这很容易实现,特别是当你使用jquery库的时候;

http://api.jquery.com/jquery.ajax/

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/37790152

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档