I'm trying to insert a row into the Friend table if the username being entered already exists in table User. My code works if I remove the WHERE EXISTS
statement but does not work with it.
$username = $_POST["username"];
$friendname = $_POST["friendname"];
$friend = $friendname;
$statement = mysqli_prepare($con, "INSERT INTO Friend (username, friend_username)
VALUES(?,?) WHERE EXISTS (SELECT * FROM User WHERE username = ?)");
mysqli_stmt_bind_param($statement, "sss", $username, $friendname, $friend);
mysqli_stmt_execute($statement);
mysqli_stmt_close($statement);
mysqli_close($con);
Debug:
PHP Notice: Undefined index: username in G:\PleskVhosts\playchesswithbrandon.net\httpdocs\UpdateFriendName.php on line 3 PHP Notice: Undefined index: friendname in G:\PleskVhosts\playchesswithbrandon.net\httpdocs\UpdateFriendName.php on line 4 PHP Warning: mysqli_stmt_bind_param() expects parameter 1 to be mysqli_stmt, boolean given in G:\PleskVhosts\playchesswithbrandon.net\httpdocs\UpdateFriendName.php on line 8 PHP Warning: mysqli_stmt_execute() expects parameter 1 to be mysqli_stmt, boolean given in G:\PleskVhosts\playchesswithbrandon.net\httpdocs\UpdateFriendName.php on line 9 PHP Warning: mysqli_stmt_close() expects parameter 1 to be mysqli_stmt, boolean given in G:\PleskVhosts\playchesswithbrandon.net\httpdocs\UpdateFriendName.php on line 10