Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/243.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 当用户存在时,找不到请求的URL_Javascript_Php_Jquery_Database_.htaccess - Fatal编程技术网

Javascript 当用户存在时,找不到请求的URL

Javascript 当用户存在时,找不到请求的URL,javascript,php,jquery,database,.htaccess,Javascript,Php,Jquery,Database,.htaccess,我有一个按钮“添加到收藏夹”,一旦点击,它应该存储(在数据库上)谁发送了收藏夹请求以及它被发送给谁的详细信息 但是,对于所有的功能代码(我认为应该可以使用),当我单击“添加到收藏夹”按钮时,我会收到以下消息: Not Found The requested URL /www/profile.php was not found on this server. profile.php工作正常,但单击按钮时会出现错误。此外,单击按钮时,url显示http://localhost/Freddy(Fre

我有一个按钮“添加到收藏夹”,一旦点击,它应该存储(在数据库上)谁发送了收藏夹请求以及它被发送给谁的详细信息

但是,对于所有的功能代码(我认为应该可以使用),当我单击“添加到收藏夹”按钮时,我会收到以下消息:

Not Found
The requested URL /www/profile.php was not found on this server.
profile.php
工作正常,但单击按钮时会出现错误。此外,单击按钮时,url显示
http://localhost/Freddy
(Freddy是登录用户的用户名)。这让我相信
$user\u\u var
(见下面的代码)的实现——但我就是不能对它掉以轻心

按钮

 <form action="<?php echo $username; ?>" method="post"> 
     <input type="submit" class="send_message" name="sendmsg" value="Send Message"/>
     <input type="submit" class="add_to_fav" name="addfriend" value="Add to Favourites"/>
 /form>
我还添加了一个.HTACCESS文件以使URL看起来更好,这可能是导致此错误的原因

.HTACCESS

RewriteBase /www/
RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1
例如,假设我在索引页上:
localhost/index.php
。我想直接转到Alice的个人资料页面,所以不用编写
localhost/index.php?u=Alice
,使用重写规则,我只需编写
localhost/index.php/Alice

问题
为什么在单击“添加到收藏夹”按钮时,我会被重定向到“未找到”页面?

当您单击该按钮时,它会请求哪个链接?这两个文件是否在www中的同一文件夹中?将您的整个表格作为well@Juakali92profile.php和.HTACCESS中的两个文件?在这种情况下,是的。这两个文件都存在于www文件夹中(Wamp>www>,在那里可以找到我的所有网页以及.htaccess)。@ааа-单击按钮后,它将最终将数据发送到数据库(尚未实现)。目前,if语句中的代码不起作用,所以我还没有开始实现将数据发送到数据库的功能。
if (isset($_GET['u'])) {
    $user_u_var = mysqli_real_escape_string($connect,$_GET['u']);
    if (ctype_alnum($user_u_var)) { //check if the user exists
    $check = mysqli_query($connect, "SELECT username, first_name FROM users WHERE username='$user_u_var'");
    if (mysqli_num_rows($check)===1) {
        $get = mysqli_fetch_assoc($check);
        $user_u_var = $get['username'];
        $fname = $get['first_name'];    
    } else { // refresh page 
        // if the user doesnt exist i.e. ?u=fakeUser - it will redirect them to the index page.
        echo "<meta http-equiv=\"refresh\" content=\"0; url=http://localhost/index.php\">"; 
        exit();
        }
    }
}
<?php 
session_start();
if (!isset ($_SESSION["user_login"])){      
    header("Location:index.php");
} else {
    $username = $_SESSION["user_login"];
}
?>
RewriteBase /www/
RewriteEngine On

RewriteRule ^([a-zA-Z0-9_-]+)$ profile.php?u=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ profile.php?u=$1