当我点击提交按钮时,我在调用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, '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
}
}
}
?>
最后一个isser($ GET ['submit']和函数调用form.What错误我找不到解决方案,它只是刷新页面但是doenst发送mysql_query。功能我打电话是这样的:
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')");
}}}
请帮助我,我是php的新手,这让我很烦恼,自从昨天晚上试图解决它以来我一直坚持这个。我真的没有看到问题是什么。我怎么改变我的代码?一切都很完美期待friend_request()函数的一部分。
答案 0 :(得分:0)
username
输入缺失,基于username
允许加入块if (isset($_GET['username']) === true and empty($_GET['username']) === false) {
<form action="">
<input type="text" name="username" value="your value">
<input type="submit" name="submit" value="Send friend request!">
</form>