输入问题 mysql php html

发布于 2024-09-05 02:33:41 字数 525 浏览 1 评论 0原文

(Q1)嗨,我在项目中使用文本框,但无法接收键入的值

<textarea rows="5" cols="60"> Type your suggestion </textarea>
<br>
<input type="submit" name="sugestao" value="Submit" />

抱歉,我不知道如何“杀死”html 代码,这就是为什么 <失踪了。

我从该文本框中获得的数据库列中的所有内容都是“提交”,我希望接收文本区域中写入的所有内容。如何使输入的值相等?

(Q2)如何确保我只存储我在数据库中设置、声明的相同类型(int、varchar、text)。例如:age(int),但如果有人在输入中键入“abc”,它将作为值 0 存储在我的数据库中。我怎样才能禁止这一点,并且只在它只是 int 且所有其他字段(如姓名、电子邮件)都已填写时保存年龄?如果仍然可能警告用户他输入了错误的内容,则无需说明错误所在。

抱歉有任何英语错误,感谢您的关注。

(Q1)Hi I'm using textbox in my project and I can't receive the values that are typed

<textarea rows="5" cols="60"> Type your suggestion </textarea>
<br>
<input type="submit" name="sugestao" value="Submit" />

Sorry I don't know how to 'kill' html code, that's why < is missing.

All I'm getting in the column of the database from this text box is "Submit", I'd like to receive whatever is written in the text area. How can I make the value equal whaterever is typed?

(Q2) How can I make sure that I'll only store the same type(int,varchar,text) that I setted,declared in the database. For example: age(int), but if someone types "abc" in the input it will be stored in my database as the value 0 . How can I forbid this, and only save the age when it's just int and all the other fields(like name, email) are filled ?. And if is still possible warn the user that he is typing something wrong, don't need to say where.

Sorry for any mistake in English and Thanks for the attention.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

情归归情 2024-09-12 02:33:41

您的文本区域需要一个 name 属性,否则,当您提交表单时,您输入的文本不会被发送。

<form method="post" action="your_handler.php">
<textarea rows="5" cols="60" name="question">Type your suggestion</textarea>
<input type="submit" name="sugestao" value="Submit" /> 
</form>

对于第二个问题,您可以在客户端(使用 JavaScript)、服务器端(使用您使用的任何语言)或两者上实现输入验证。

以年龄验证为例,您需要验证两件事:

  1. 您有一个数字
  2. 等于或大于 16

使用 PHP,您可以这样检查:

if( (int) $_POST['age'] > 15) {
   // insert the record
} else {
   // display error message
}

You need a name attribute for your textarea, otherwise, when you submit the form, the text you have entered is not sent.

<form method="post" action="your_handler.php">
<textarea rows="5" cols="60" name="question">Type your suggestion</textarea>
<input type="submit" name="sugestao" value="Submit" /> 
</form>

For your second question, you can implement input validation on client side (with javascript), server side (with whatever language you are using), or both.

For age validation as an example you want to validate two things:

  1. You have a number
  2. It's equal to, or greater than say 16

With PHP you check this way:

if( (int) $_POST['age'] > 15) {
   // insert the record
} else {
   // display error message
}
伴梦长久 2024-09-12 02:33:41

我认为您在文本区域中缺少 name="" 属性。如果添加它,您将在 $_POST 数组中收到它的值。例如,name="abc" 将导致 $_POST['abc']

对于第二个问题,您需要进行表单验证。在Google里找这个,这是一个基本任务。

I think that you are missing the name="" attribute in your textarea. If you add it, you will receive its value in the $_POST array. For eaxmple, name="abc" will result in $_POST['abc']

For the second question, you need to do form validation. Look for this in Google, it is a basic task.

清君侧 2024-09-12 02:33:41

如果您想在保存之前检查数据类型,可以使用 PHP 的内置方法来执行此操作。 php 有很多方法可以实现此目的 - is_numeric()is_string()is_float() 等等。当数据传递到服务器时,POST 数据最初将采用字符串形式,因此您可能必须在运行这些方法中的任何一个之前对其进行转换 ($castVar = (int)$var)

If you want to check for data types before saving, you can use PHP's built in methods to do so. There are lots of methods for this with php - is_numeric(), is_string(), is_float() and so forth. When the data is passed to the server, the POST data will initially be in string form, so you may have to cast it ($castVar = (int)$var) before you run any of these methods.

踏雪无痕 2024-09-12 02:33:41

q2。您无法自动执行此操作,但可以手动执行此操作。
只需在表单处理程序脚本中添加验证代码即可。

if ($_POST['age'] < 13 or $_POST['age'] > 110) $err[] = "Wrong age value!";

q2. you can't do it automatically but it can be done manually.
Just add a validation code in the form handler script.

if ($_POST['age'] < 13 or $_POST['age'] > 110) $err[] = "Wrong age value!";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文