用另一个字段的值填充一个字段 [英] Populating a field with values from another field

查看:151
本文介绍了用另一个字段的值填充一个字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对PHP和javascript很陌生,如果这是一个简单的问题,请向我道歉.我有一个带有下拉框和GO按钮的表单,用于选择文档(从下拉框)并导航到它们(转到按钮).我想做的是,当下拉列表被选中时,从数据库中检索文档URL并将其传递给按钮,因此单击该按钮会将用户发送到文档. MySQL查询如下所示:

I'm quite new with PHP and javascript, so apologize me if this is an easy question.I have a form with a dropdown box and a GO button, used to select documents (from the dropdown box) and navigate to them (GO button). What I would like to do is to retrieve the document URL from the database when the dropdown item is selected and pass it to the button, so when clicked it sends the user to the document. The MySQL query looks like this:

SELECT `Bruel_URL` FROM `mpctz_rsform_bruels` WHERE `Bruel_ID` = GO.value

所以问题是:

  1. 如何从Bruel_ID获取值并将其传递给MySQL查询(我在上面的查询中将其表示为GO.value)?
  2. 如何检索和存储Bruel_URL?
  3. 如何编写将用户发送到Bruel_URL的JavaScript函数? 感谢您的帮助!
  1. How do I get the value from the Bruel_ID and pass it to the MySQL query (I've represented it as GO.value in the query above)?
  2. How do I retrieve and store the Bruel_URL?
  3. How can I write a javascript function that sends the user to the Bruel_URL? Thanks for your help!

丹妮

推荐答案

在我看来,这是没有JavaScript的PHP重定向的最简单方法.

In my opinion it's the simpliest way just PHP redirect without javascript.

 <form action="" method="post">
    <select name="document">
        <option value="1">Document 1</option>
        <option value="2">Document 2</option>
    </select>
    <input type="submit"/>
</form>

<?php 
if(isset($_POST['document'])){
    // using PDO connection
    // select row
    $stmt = $pdo->prepare('SELECT `Bruel_URL` as url FROM `mpctz_rsform_bruels` WHERE `Bruel_ID` = :document_id');
    $stmt->bindValue(':document_id', $_POST['document']. PDO::PARAM_INT);
    $stmt->execute();
    $row = $stmt->fetch(PDO::FETCH_ASSOC);
    // if url exists - redirect
    if(!empty($row['url'])){
        header('Location:'.$row['url']);
    }
}

这篇关于用另一个字段的值填充一个字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆