dqve65954 2014-04-22 11:43
浏览 149

PHP表单包含必填字段

I want to creat a form which can connect to mysql and can insert records which I have done. But now I want to make some fields mandatory, username and car for example. Also showing the error field as required or "name cannot have numbers". Stuff like that. I am unable to figure it out.

Some help please:

I have index.html

<form action="insert.php" method="post">
Nume: <input type="text" name="name"><span class="error">* <?php echo $error;?></span><br>
Prenume: <input type="text" name="prenume"><br>
Masina: <input type="radio" name="masina" value="vito"> (Vito)
<input type="radio" name="masina" value="skoda"> (Skoda)
<input type="radio" name="masina" value="skoda2"> (Skoda)
<input type="radio" name="masina" value="audi"> (Audi)<br><br>

Data: <input type="date" name="data"/><br>
Ora: <input type="time" name="ora"/><br>


Destinatie:<input type="text" name="destinatie"><br>

KM la iesire: <input type="text" name="kmiesire"><br>
KM la intrare: <input type="text" name="kmintrare"><br>

<input type="submit">

and Insert.php

<?php
include "connect.php";

$order = "INSERT INTO data_employees
            (name, prenume, masina, data, ora, destinatie, kmiesire, kmintrare)
            VALUES 
            ('$_POST[name]',
            '$_POST[prenume]',
            '$_POST[masina]','$_POST[data]','$_POST[ora]','$_POST[destinatie]',
            '$_POST[kmiesire]','$_POST[kmintrare]'
            )";

if (mysqli_query($con,$order)){
    header('Location: index.html');
}else{
    echo("Input data is fail");
}

?>
  • 写回答

3条回答 默认 最新

  • doufuxing8691 2014-04-22 11:47
    关注

    you have to check rules before the query...

    if(empty($_POST['name'])){
       echo "Name Required";
    }
    elseif(bla bla){
      echo "something"
    }
    else {
       // your query....
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写