简体   繁体   English

smarty tpl 文件中的 PHP $_POST 不起作用

[英]PHP in a smarty tpl file $_POST doesnt work

in my where i use smarty to connect everything tpl file i have a form在我使用 smarty 连接所有 tpl 文件的地方我有一个表格

<form method="post">
    <div class="form-group"><label for="address"><strong>Address</strong></label><input class="border rounded-pill form-control" type="text" value='{$address}' name="address"></div>
        <div class="form-row">
            <div class="col">
                <div class="form-group"><label for="city"><strong>City</strong></label><input class="border rounded-pill form-control" type="text" value='{$city}' name="city"></div>
            </div>
            <div class="col">
                <div class="form-group"><label for="country"><strong>Country</strong></label><input class="border rounded-pill form-control" type="text" value='{$country}' placeholder="The Netherlands" name="country"></div>
            </div>
        </div>
        <div class="form-group"><label for="phonenumber"><strong>Phone Number</strong></label><input class="border rounded-pill form-control" type="text" value='{$phone}' placeholder="+1 (0)1 234 56 789" name="phonenumber"></div>
        </div>
        <div class="card-body" style="background: #f5f5f5;">
            <button class="btn btn-primary btn-sm" type="submit" name="contactsend">Save&nbsp;Settings</button>
        </div>
    </div>
</form>

But if i try to contact it in my php file但是如果我尝试在我的 php 文件中联系它

if(isset($_POST['contactsend'])) {
  $inaddress = mysqli_real_escape_string($db, $_POST['address']);
  $incity = mysqli_real_escape_string($db, $_POST['city']);
  $insert = $db->query("UPDATE accounts SET address = ".$inaddress.", city = ". $incity ." WHERE id = ".$id_user."");
}

it wont get the contactsend button if i press it, so it also wont update the tables.如果我按下它,它不会得到联系人发送按钮,所以它也不会更新表格。 can someone please help me?有人可以帮帮我吗?

that form is posting to it's own page... is the php script in the same file as the render script?该表单正在发布到它自己的页面...... php 脚本与渲染脚本在同一个文件中吗? If not you need to set the action="" attribute of the form to the php script url如果不是,您需要将表单的 action="" 属性设置为 php 脚本 url

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

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