PHP调用函数失败
单击“提交”按钮时调用php函数时出现问题:PHP调用函数失败,php,function,Php,Function,单击“提交”按钮时调用php函数时出现问题: <?php if (isset($_GET['username']) === true and empty($_GET['username']) === false) { $username = $_GET['username']; if(user_exists($username) === true) { $profile_user_id = user_id_from_username($username, 'us
<?php
if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
$username = $_GET['username'];
if(user_exists($username) === true) {
$profile_user_id = user_id_from_username($username, 'username');
$my_id = $_SESSION['user_id'];
$profile_data = user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
?>
<h1><?php echo $profile_data['first_name']; ?>'s Profile</h1>
<?php
if($profile_user_id != $my_id) {
$check_friend_query = mysql_query("SELECT id FROM friends WHERE (user_one='$my_id' AND user_two='$profile_user_id') OR (user_one='$profile_user_id' AND user_two='$my_id')");
if(mysql_num_rows($check_friend_query) > 0) {
echo '<a href="">Already Friends </a>- <a href="">Unfriend '. $profile_data['username'] .'</a>';
} else {
$from_query = mysql_query("SELECT id FROM friend_request WHERE `from` = '$profile_user_id' AND `to` = '$my_id'");
$to_query = mysql_query("SELECT id FROM friend_request WHERE `from` = '$my_id' AND `to` = '$profile_user_id'");
if(mysql_num_rows($from_query) == 1) {
echo '<a href="#">Ignore</a> or <a href="">Accept</a>';
} elseif(mysql_num_rows($to_query) == 1){
echo '<a href="#">Cancel Request</a>';
} else {
if(isset($_GET['submit'])) {
friend_request();
header('Location: '.$profile_user_id);
exit();
}
?>
<form action="">
<input type="submit" name="submit" value="Send friend request!">
</form>
<?php
}
}
}
?>
请帮帮我,我是php新手,这让我很恼火,从昨天晚上开始我就一直在想办法解决这个问题。我真的不知道有什么问题。我如何更改代码?除了friend_request()函数部分之外,一切都很好。你的表单中的
用户名输入缺失,基于允许进入块的username
值if(isset($\u GET['username'])==true,空($\u GET['username'])==false){
谢谢,但这只是一个好友请求按钮,它不需要文本类型。我在阻止中允许的用户名用于其他目的。由于您的代码需要用户名,您可以将用户名作为隐藏值传递,如仍然只需刷新页面添加到URL:Username?Username=Username&submit=Send+friend+request%21Am不是当然,我理解你的评论!
function friend_request() {
if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
$username = $_GET['username'];
if(user_exists($username) === true) {
$profile_user_id = user_id_from_username($username, 'username');
$my_id = $_SESSION['user_id'];
$profile_data = user_data($profile_user_id, 'username', 'first_name', 'last_name', 'email', 'profile');
mysql_query("INSERT INTO friend_request VALUES('', '$my_id', '$profile_user_id')");
}}}
<form action="">
<input type="text" name="username" value="your value">
<input type="submit" name="submit" value="Send friend request!">
</form>