我似乎无法插入此插件。什么都没有插入。我现在尝试了几种方法,但都没有工作。与db的连接是存在但没有插入。
$insert = "INSERT INTO
friendshipTable
( user_a_memberID , user_b_memberID )
VALUES ($member_id,$addFriendID)";
$resultx = mysqli_query($connExt, $insert);
答案 0 :(得分:3)
查询实际上将$ connExt视为未定义是没有问题的,因为它是一个范围问题。您可以在本地功能中使用global $connExt;
或代码如下......
<form action="friendship.php" method="post">
<input type="text" name="addfriend" placeholder="add friend">
<input type="text" name="member_id" placeholder="member id">
<input type="submit">
</form>
<?php
$connExt = mysqli_connect("localhost", "root", "root", "test");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: ".mysqli_connect_error();
}
if ( isset($_POST['addfriend']) && $_POST['addfriend']) {
$addFriend = $_POST['addfriend'];
$member_id = $_POST['member_id'];
addFriend($addFriend, $member_id, $connExt);
}
function addFriend($addFriendID, $member_id, $connExt) { //add friend acts as a follow based system
//create db query
$insert = "INSERT INTO friendshipTable( user_a_memberID , user_b_memberID )
VALUES ('$member_id','$addFriendID');";
$resultx = mysqli_query($connExt, $insert);
echo "addfriend: ".$addFriendID;
echo '<br />';
echo "member_id: ".$member_id;
echo '<br />';
echo "woop!";
echo '<br />';
echo $resultx;;
//return status
}
function unFriend() {
}
?>