提交表单时验证错误 [英] Validation error in submitting the form

查看:73
本文介绍了提交表单时验证错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果空名称提交表单,则表示显示错误消息。我使用一个html页面和一个php页面。我得到的是尽管名称不存在,但它将存储在其他数据中,如年龄到数据库中。我需要答案为文本字段一侧的[* Username missing]而不是下一个表格。 KIAND帮助请



我尝试了什么:



<? php



$ link = mysqli_connect(localhost,root,,training);



if(isset($ _ POST ['submit']))

{



$ fname = $ _POST ['fname '];



if(空($ _ POST [name])){

$ fnameErr =Missing;

}

else {

$ fname =($ _POST [fname]);

}

$ sql =INSERT INTO record(Name)VALUES('$ fname');



$ op = mysqli_query($ link,$ sql );

if($ op){

echo学生信息已插入;

}

else {

echonot inserted;

}



}

mysqli_close( $ link $;

?>

While submitting the form if empty name means error message to show. I using one html page and one php page . What i am getting is eventhough the name is not in also it will storing in other data given like age into database. I need the answer as [* Username missing ] on the side of textfield and not going to next form. KIndly help pls

What I have tried:

<?php

$link = mysqli_connect("localhost", "root", "", "training");

if(isset($_POST['submit']))
{

$fname = $_POST['fname'];

if (empty($_POST["name"])) {
$fnameErr = "Missing";
}
else {
$fname = ($_POST["fname"]);
}
$sql = "INSERT INTO record (Name) VALUES ('$fname')";

$op = mysqli_query($link,$sql);
if($op){
echo "Student info inserted";
}
else{
echo "not inserted";
}

}
mysqli_close($link);
?>

推荐答案

link = mysqli_connect(localhost,root,,training );



if(isset(
link = mysqli_connect("localhost", "root", "", "training");

if(isset(


_POST ['submit']))

{


_POST['submit']))
{


fname =


这篇关于提交表单时验证错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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