dongye1942 2017-12-17 08:10
浏览 39
已采纳

运行一些MySQL代码的HTML按钮然后打开一个链接[关闭]

I was put in the sin-bin for a week after my last question, so if anyone has problems with this one, please let me know first and I'll do my best to clear things up before I get put on hold.

Anyway, on to my problem:

I have a page that has a text box for a reference number. What I want is to run a mysql query that will check if that value exists on a table, if it doesn't, create a new line for it. I don't think I'll have too much trouble with this, I've managed to get the code to write to the table (although, at the moment that's regardless of whether it exists or not).

What's really got me stumped is how do I include their entered reference in a URL that should load after the query has been completed. Would I need to somehow pass something from the PHP to javascript?

The intended URL will be something along the lines of www.foo.com/bar?=REF <--ref being the user-entered value.

As requested, the code I've used so far:

<html>
<head>
<meta charset="UTF-8">
<title>Application Form Prototype</title>

</head>

<hr width="100%" STYLE="position:absolute; top:220px">
<!--Breadcrumb Text-->
<hr width="100%" STYLE="position:absolute; top:260px">
<body>
<div style="position: absolute; TOP: 300px; left:100px; width: 75%">
<h1 class="heading-xlarge" style="Padding-bottom: 0px; margin-bottom: 30px; margin-top: 30px">Welcome to the prototype for the application form</h1>
<p class="lede">Please be aware that this prototype is <b>not</b> secure and as such, please enter only non-sensitive, non-personal data</p>
<p class="lede">Pleae enter a memorable reference for your application in the box below. If you are returning to a previous session, please enter the reference you assigned at that point</p>
<h1></h1>
<form action="" method="post">
    <label>Reference</label>
    <input type="text" name="ref" id="ref" required="required" placeholder="Please Enter reference"/><br /><br />
    <input type="submit" value=" Submit " name="submit" /><br />
</form>

<?php
if(array_key_exists('ref', $_POST)) {
    include 'connection.php';
    $ref = $_POST['ref'];
    $query = mysqli_query($mysqli, 'INSERT INTO answers (strRef) VALUES (\'' .$ref . '\');');
}
?>

</div>
</body>
</html>

I did try a bit of javascript, but calling an onclick event seemed to bypass my php, is that right? or was my DB just playing up?

  • 写回答

1条回答 默认 最新

  • dongluxin6711 2017-12-17 08:39
    关注

    <?php
    if(array_key_exists('ref', $_POST)) {
        include 'connection.php';
        $ref = $_POST['ref'];
        $query = mysqli_query($mysqli, 'INSERT INTO answers (strRef) VALUES (\'' .$ref . '\');');
    }
    
    header('Location: http://foo.com/bar?=REF'.$ref.');
    ?>

    try something like this

    </div>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料
  • ¥15 使用R语言marginaleffects包进行边际效应图绘制
  • ¥20 usb设备兼容性问题
  • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊
  • ¥15 安装svn网络有问题怎么办
  • ¥15 vue2登录调用后端接口如何实现