dqm88684 2017-04-21 01:25
浏览 118

从HTML Javascript表单中读取数据

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. 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. 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. 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

  • 写回答

1条回答 默认 最新

  • dongzhun1857 2017-04-21 01:32
    关注

    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. You would not handle form input from javascript, until after your PHP has done something with it. Here is a refresher: https://www.w3schools.com/php/php_forms.asp

    <?php echo $_POST["q3_fullName3[first]"]; ?> would output the value into the HTML page allowing you to do something like this:

    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.

    It sounds like you might want to get a book about PHP + MySQL since interacting with a database is a more advanced topic. I can recommend this one: https://www.amazon.com/Learning-PHP-MySQL-JavaScript-Javascript-ebook/dp/B00QUBHNFI/ref=mt_kindle?_encoding=UTF8&me=

    评论

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!