简体   繁体   English

从HTML Javascript形式读取数据

[英]Reading in Data from HTML Javascript form

I am creating a website backed by a database. 我正在创建一个由数据库支持的网站。 I have created my forms that collect the information but now i need to read in the input from the form when user clicks submit and process it for mySQL. 我已经创建了收集信息的表单,但是当用户单击提交并为mySQL处理它时,我需要从表单中读取输入。 I am having my form action be a new page but I can't figure out how to read in value from the previous page. 我将表单操作设为新页面,但无法弄清楚如何从上一页读取值。 My Form code looks like this: 我的表单代码如下所示:

<div data-wrapper-react="true">
        <span class="form-sub-label-container" style="vertical-align:top;">
          <input type="text" id="first_3" name="q3_fullName3[first]" class="form-textbox validate[required]" size="10" value="" data-component="first" />
          <label class="form-sub-label" for="first_3" id="sublabel_first" style="min-height:13px;"> First Name </label>
        </span>

When user hits submit the action for this page is connect.php. 当用户点击时,提交此页面的操作是connect.php。 I am not sure how to read in the value there. 我不确定如何在其中读取值。 I tried this following command: 我尝试了以下命令:

document.getElementById("first_3").value; 

This just displays the code on blank html page for connect.php and not read in the values. 这只会在空白html页面上显示connect.php的代码,而不会读取值。 The data from the forms needs to be processed into different tables if someone can help with that as well that would be great. 如果有人也可以帮忙,那么表单中的数据需要处理到不同的表中。 Thanks 谢谢

Form handling, in the way you are describing, is something you do server-side. 按照您描述的方式,表单处理是在服务器端执行的操作。 PHP is handled on the server first where PHP tags can be evaluated to HTML, then this is returned to the browser. 首先在服务器上处理PHP,然后将PHP标记评估为HTML,然后将其返回给浏览器。 You would not handle form input from javascript, until after your PHP has done something with it. 您将无法处理来自javascript的表单输入,除非您的PHP完成了一些操作。 Here is a refresher: https://www.w3schools.com/php/php_forms.asp 这是一个复习课程: https : //www.w3schools.com/php/php_forms.asp

<?php echo $_POST["q3_fullName3[first]"]; ?> <?php echo $_POST["q3_fullName3[first]"]; ?> would output the value into the HTML page allowing you to do something like this: <?php echo $_POST["q3_fullName3[first]"]; ?>会将值输出到HTML页面,使您可以执行以下操作:

console.log("<?php echo $_POST["q3_fullName3[first]"]; ?>");

If you view source of the HTML, you will notice the PHP tag is gone and replaced with the form field value. 如果查看HTML的源代码,您会注意到PHP标记已消失,并被表单字段值替换。

It sounds like you might want to get a book about PHP + MySQL since interacting with a database is a more advanced topic. 听起来您可能想要获取一本有关PHP + MySQL的书,因为与数据库交互是一个更高级的主题。 I can recommend this one: https://www.amazon.com/Learning-PHP-MySQL-JavaScript-Javascript-ebook/dp/B00QUBHNFI/ref=mt_kindle?_encoding=UTF8&me= 我可以推荐以下一种: https : //www.amazon.com/Learning-PHP-MySQL-JavaScript-Javascript-ebook/dp/B00QUBHNFI/ref=mt_kindle?_encoding=UTF8&me=

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM