SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2013
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why is my code not printing?

    I'm designing a bookmarking website for a school project and it all looks fine, but when I enter my input nothing changes. i think the problem may be with sessions?

    Code PHP:
    <?php
    session_start();
     
    if(!isset($_SESSION['where'] ) ){
        $_SESSION['where'] = array();
    }
                        function save($where, $title, $link, $notes){
                            $desc = school();
                            $desc['title'] = $title;
                        array_push($_SESSION[$where], $desc);
                        }
                        function show($desc) {
                            $items = $_SESSION[$school];
                            foreach($items as $item);
                                $title = $item['title'];
                                $link = $item['link'];
                                $notes = $item['notes'];
                        }
     
    ?>

    Code HTML4Strict:
    <html>
        <head>
            <link rel="stylesheet" type="text/css" href="external.css"/>
        </head>
     
        <body>
     
            <div id="header">
                <h1>Bookmarker</h1><br/>
                <div id="book"> <img src="http://www.iconshock.com/img_jpg/SEVEN/general/jpg/256/book_icon.jpg" style="height:200px;width:200px;"> 
                </div>
                </div>
     
            <div id="menu">
                <b>Menu</b><br>
                <a href='tester.php'>Main Page</a><br>
                <a href='about.php'>About Bookmarker</a></div>
     
     
            <div id="content">
                    <form action='' method='GET'>
                            <center>
                                <input type="text" name="title" placeholder="Title of link"/>
                                <input type="text" name="link" placeholder="Link"/>
                                <input type="text" name="notes" placeholder="Notes/comments"/>
                        <input type="submit" value="Save!"/>
                            </center>                    
                    </form>
            <div>
     
                <div id="school">
                      <p style="
                    font-size:14pt;
                    color:#67380E;
                    font-weight:bold;
                    ">
                        Saved
                    </p>
    Code PHP:
                <?php
                if( isset( $_SESSION['title']) && isset( $_SESSION['link']) && isset( $_SESSION['notes']))
                    print("<a href=$link>$title</a><br/>$notes");
                ?>
                </div>

    the website looks like this right now:
    Screen Shot 2013-05-02 at 2.02.12 PM.png

  2. #2
    Hosting Team Leader silver trophybronze trophy
    cpradio's Avatar
    Join Date
    Jun 2002
    Location
    Ohio
    Posts
    5,122
    Mentioned
    152 Post(s)
    Tagged
    0 Thread(s)
    $title, $link, and $notes are not available in the scope that you are trying to use them in. $_SESSION['title'], $_SESSION['link'], and $_SESSION['notes'] might be, so try substituting the prior three variables with those instead. Something like:
    PHP Code:
    print("<a href={$_SESSION['link']}>{$_SESSION['title']}</a><br/>{$_SESSION['notes']}"); 

  3. #3
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,496
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    The values from the form are available in the $_GET array. In the code you posted you don't use those values anywhere?
    And where do you use the 'save' and 'show' functions from the first php code part you posted?

    And please post the entire code (php and html) without cutting it to pieces. It's hard to understand how things are connected this way.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •