用户单击按钮时,在数据库中插入uid1和uid2

时间:2014-05-20 21:56:35

标签: javascript php mysql ajax twitter-bootstrap

<?php uid1= 1; $uid2= 2; ?>

<form class="contact" method="post">
<button value=" Send" class="btn btn-success" type="submit" id="submit">Add Friend</button></form>

if (isset($_POST['submit'])){

mysqli_query($mysqli, "INSERT INTO friends (uid1, uid2) values ('$uid1', '$uid2')") or die(mysql_error());
}

1 个答案:

答案 0 :(得分:0)

在开场线..你错过了uid1的$。其次,您需要以hiddent文本发回值。

<?php $uid1= 1; $uid2= 2; ?>

<form class="contact" method="post">
<input type="hidden" name="uid1" value="<?= $uid1 ?>" />
<input type="hidden" name="uid2" value="<?= $uid2 ?>" />
<button value=" Send" class="btn btn-success" type="submit" id="submit">Add Friend</button></form>

if (isset($_POST['submit'])){

mysqli_query($mysqli, "INSERT INTO friends (uid1, uid2) values ('". $_POST["uid1"] ."', '". $_POST["uid1"] ."')") or die(mysqli_error());
}