开发者

HTML Formular is redirecting wrong!

So, my formular is redirecting to the wrong site!

Look at my example:

ATM I've got the internet address: http://localhost/myworkspace/mywebsite/index.php

It's hosted on a localhost-xampp server. It's homepage is: http://localhost/xampp/

Ok ... Now I tried several things to get into the file where the script is that is working with the data of the formular:

<form action="index.php">

-> I'm getting redirected to the Xampp Homepage

<form action="index.php?mod=home">

-> I'm getting redirected to the Xampp Homepage

<form action="myworkspace/mywebsite/index.php">

-> I'm getting redirected on "http://localhost/myworkspace/mywebsite/myworkspace/mywebsite/index.php"

(the arrows express what happens when clicking on "send")

Why is this happening? As seen in the examples, the browser is not moving outside the myworkspace/mywebsite-folders. But still, it loads the index.php which is located in localhost/xampp (it's localhost/index.php). If you see my original link of the website, there actually is an index.php file in "myworkspace/mywebsite".

Here's some code of me:

the addguestbook.php, which is included into the index.php (see below)

<?php

//******************************************************//
//********************Database stuff********************//
//******************************************************//
$host="localhost";                  // Host name
$username="root";                       // Mysql username
$password="";                       // Mysql password
$db_name="mywebsite";               // Database name
//********************Tables***************************//
$tbl_name="guestbook";              // Guestbook
echo $hostname.$path.$get;
if ($_SERVER['REQUEST_METHOD'] == 'POST'){

    $name = $_POST['name'];
    $email = $_POST['email'];
    $website = $_POST['website'];
    $comment = $_POST['comment'];
    $datetime = date("l, jS M Y, g:i a"); //date time

    // Connect to server and select database.
    mysql_connect($host, $username, $password)or die("cannot connect server: ".mysql_error());
    mysql_select_db($db_name)or die("cannot select DB: ".mysql_error());

    $sql="INSERT INTO ".$tbl_name."(id, name, email, website, comment, datetime)VALUES('".$post_id."', '".$name."', '".$email."', '".$website."', '".$comment."', '".$datetime."')";
    $result=mysql_query($sql);

    mysql_close();

} else 
?>
<form method="post" action="myworkspace/mywebsite/index.php">
    <table border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="name" type="text"
                value="Name *" size="40" maxlength="30" /></td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="email" type="text"
                value="E-Mail (won't become displayed)" size="40" maxlength="40" />
            </td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><input
                class="guestbookInputFieldText" name="website" type="text"
                value="Website" size="40" maxlength="50" /></td>
        </tr>
        <tr>
            <td class="guestbookFormCell" colspan='2'><textarea
                    class="guestbookInputFieldText" name="comment" cols="37" rows="5">Comment *</textarea>
            </td>
        </tr>
        <!-- 
        <tr>
            <td>CAPTCHA</td>
        </tr>
         -->
        <tr>
            <td><button class="guestbookFormCell guestbookButton" type="submit"
                    name="submit">
                    <span class='guestbookButtonText'>Send</span>
                </button></td>
            <td><button class="guestbookFormCell guestbookButton" style="float:right;"type="reset"
                    name="reset">
                    <span class='guestbookButtonText'>Reset</span>
                </button></td>
        </tr>
    </table>
</form>

and the index.php (it's pretty big. most of it is just a design-structure, so ignore the html stuff. it's just divs and tables.

<html>
<head>

<title>JustBasti's website</title>

<script type="text/javascript" src="lightbox/js/prototype.js"></script>
<script type="text/javascript"
    src="lightbox/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="lightbox/js/lightbox.js"></script>
<link rel="stylesheet" href="lightbox/css/lightbox.css" type="text/css"
    media="screen" />
<link rel="stylesheet" type="text/css" href="style.css" />

</head>
<body>
<?php
session_start();
// Path-parameters for link-building
$hostname = $_SERVER['HTTP_HOST'];
$path = $_SERVER['PHP_SELF'];
$_SESSION['basepath'] = dirname($_SERVER['PHP_SELF']);
?>

    <div id='top'>
        <div id='header'>
            <div id='headerText' class='lightText text bigText'>
                <div>
                    Hello, My name is <font class='blueText'>Sebastian Fast</font>
                </div>
                <div>
                    I just finished my <font class='blueText'>education in IT</font>
                </div>
                <div>
                    and am now <font class='blueText'>aiming to</font>
                </div>
                <div>
                    experience the <font class='blueText'>most wonderful places</font>
                </div>
                <div>
                    around <font class='blueText'>the world</font>
                </div>
                <div>
                    Read more about myself <font class='blueText'>here</font>
                </div>
            </div>
            <div id='headerLineBox'>
                <div class='lineTopDiv'>
                    <div id='headerTopLine' class='lineTopEnd'></div>
                </div>
                <div class='verticalLine'>
                    <div id='headerLine' class='line'></div>
                </div>
                <div class='lineBottomDiv'>
                    <div class='lineBottomEnd'></div>
                </div>
            </div>
            <div id='headerNavigation' class='lightText text bigText'>
                <div>
                    <a href='index.php?mod=home' class='lightLink'>Home</a>
                </div>
                <div>
                    <a href='index.php?mod=news' class='lightLink'>News</a>
                </div>
                <div>
                    <a href='index.php?mod=countries' class='lightLink'>Countries</a>
                </div>
                <div>
                    <a href='index.php?mod=gallery' class='lightLink'>Gallery</a>
                </div>
            </div>
        </div>
    </div>
    <div id='middle'>
        <div id='content'>
            <table>
                <!-- CONTENT -->
            <?
            // Paths
            echo "  <a href='index.php?mod=home'>Home</a>
        <a href='index.php?mod=news'>News</a>
        <a href='index.php?mod=allnews'>All News</a>
        <a href='index.php?mod=countries'>Countries</a>
        <a href='index.php?mod=gallery'>Gallery</a>
        <a href='index.php?mod=guestbook'>Guestbook</a>
        <a href='index.php?mod=admin'>Administrator</a>";

            if (!isset($_SESSION['angemeldet']) || !$_SESSION['angemeldet']) {
                include('login/login.php');
            }

            // Check which link got clicked & import data
            if (!$_GET){
                include('data/home.php');
            } elseif (isset($_GET['mod']) && !isset($_GET['post']) && !isset($_GET['album']) && !isset($_GET['country'])){
                Switch($_GET['mod']){
                    case 'home':
                        include('data/home.php');
                        exit;
                    case 'news':
                        include('data/latestPosts.php');
                        exit;
                    case 'allnews':
                        include('data/allPosts.php');
                        exit;
                    case 'countries':
                        include('data/viewCountries.php');
                        exit;
                    case 'gallery':
                        include('data/gallery.php');
                        exit;
                    case 'admin':
                        include('admin/admin.php');
                        exit;
                }
            } elseif (isset($_GET['mod']) && isset($_GET['post'])){
                $get = "?mod=".$_GET['mod']."&post=".$_GET['post'];
                $post_id = $_GET['post'];
                include('data/viewPost.php');
                include('data/guestbook.php');
            } elseif (isset($_GET['mod']) && isset($_GET['album'])){
                $get = "?mod=".$_GET['mod']."&album=".$_GET['album'];
                $post_id = $_GET['album'];
                include('data/viewAlbum.php');
                include('data/guestbook.php');
            } elseif (isset($_GET['mod']) && isset($_GET['country'])){
                $country = $_GET['country'];
                include('data/viewCountry.php');
            }
            ?>
            </table>
        </div>
    </div>
    <div id='graphicDIV'>
        <div id='graphic'></div>
    </div>
    <div id='bottom'>
        <div id='guestbook'>
            <table border='0' cellspacing='0' cellpadding='0'>
                <tr>
                    <td id='guestbookHeadline1'><font class='lightText bigText text'>Allgemeines Gästebuch</font>
                    </td>
                    <td id='guestbookTopLine' class='lineTopEnd'></td>
                    <td id='guestbookHeadline2'><font class='lightText bigText text'>Schreibe selbst</font>
                    </td>
                </tr>
                <tr id='guestbook2'>
                    <?
                    $post_id = 000000000000;
                    $get = "?mod=home";
                    ?>
                    <td id='guestbookComment'>
                    <? include('data/viewguestbook.php'); ?>
                    </td>
                    <td id='guestbookLine'></td>
                    <td id='guestbookFormular'>
                    <? include('data/addguestbook.php'); ?>
                    </td>
                </tr>
            </table>
        </d开发者_如何学Civ>
        <div id='footerLeftLine' class='lineLeftEnd'>
            <!-- LineLeftEnd -->
        </div>
        <div id='footerLine' class='horizontalLine'>
            <!-- Line -->
        </div>
        <div id='footerRightLine' class='lineRightEnd'>
            <!-- LineRightEnd -->
        </div>
        <div id='footer'>
            <div class='footerLink'>
                <!-- AdministratorLink -->
            </div>
            <div class='footerLink'>
                <!-- ImpressumLink -->
            </div>
            <div class='footerLink'>
                <!-- NewsArchiveLink -->
            </div>
        </div>
    </div>
</body>
</head>
</html>

Thanks for help!


<form action="myworkspace/mywebsite/index.php">

should be

<form action="/myworkspace/mywebsite/index.php">

What you currently have is a path relative to your current page. The path that I have given is relative to your document root, which is http://localhost.

See also:

  • Absolute and Relative Paths, from About.com
  • Path (computing), from Wikipedia
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜