textbox in html

textbox in html

本文关键字:html in textbox      更新时间:2023-09-26

这是我的代码:

<html>
<body>
  <BR><p><U>Add contact...</U></p><BR>
  Name:          <INPUT TYPE="text" NAME="firstbox">
  Id.number:     <INPUT TYPE="text" NAME="idbox">
  <?php
    session_start();
    $username=$_SESSION['UserID'];
    $s_name=$_GET['firstbox'];
    $s_id=$_GET['idbox'];
    $db = mysql_connect("???????", "???????", "");
    mysql_select_db("???????",$db);
    $result = mysql_query("SELECT * FROM contacts WHERE u_id='$username' and c_id='$s_id'",$db);
    $myrow = mysql_fetch_row($result);
    if(!$myrow) {
      mysql_query("INSERT INTO contacts(u_id, c_name, c_id) VALUES ('$username','$s_name','$s_id')",$db);
      header("Location: http://?????/protectedpage.php");
    } else {
      header("Location: http://?????contact1.htm");
    }
  ?>
</body>
</html>

是否可以检查是否在firstboxlastbox中输入了I值,如果是,连接到数据库,但如果否,不插入数据库?

是否有可能限制框中的总整数,例如,在idbox中,如果整数大于5(12345,11234,99900),则不插入数据库?

好的,我已经试过了,但它不工作

if (($s_id="") and ($_name=""))
{
header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/contact1.htm");
}
else
{
$db = mysql_connect("at-web2.comp.glam.ac.uk", "user_10003088", "Glamorgan1");
mysql_select_db("db_10003088",$db);
$result = mysql_query("SELECT * FROM contacts WHERE u_id='$username' and c_id='$s_id'",$db);
$myrow = mysql_fetch_row($result);

if(!$myrow)
    {
   mysql_query("INSERT INTO contacts(u_id, c_name, c_id) VALUES ('$username','$s_name','$s_id')",$db);
    header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/protectedpage.php");
   }
else{
    header("Location: http://at-web2.comp.glam.ac.uk/students/10003088/contact1.htm");
}
}

我添加了if语句来检查,

你所有问题的答案都是"是"。

  1. 要检查文本框是否为空,请为每个文本框添加if语句(使用文本框名称而不是"text":

    $firstbox = $_POST['firstbox'];
    If ($firstbox === "") {
        Echo "firstbox Empty";
    }
    $idbox = $_POST['idbox'];
    If ($idbox === "") {
        Echo "idbox Empty";
    }
    
  2. 检查idbox的值,使用类似的if语句:

    $idbox = $_POST['idbox'];
    If (intval($idbox) > 5) {
        Echo "idbox value greater than 5";
    }