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>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法