www.webdeveloper.com
Results 1 to 6 of 6

Thread: Submitting forms and writing data to file

  1. #1
    Join Date
    Sep 2006
    Posts
    69

    Submitting forms and writing data to file

    I'm trying to write songs to a text file and then be able to add/delete, shuffle etc within that text file.

    I'm having an issue with ending my first "IF" statement. Here is what I get they way it is currently written --

    You are viewing this page because you have submitted a song to our list
    You have not entered a song, please use link below and enter a song

    "; die (); } has been added to Duff'sSong list!

    You have add a song.

    To go back to the main menu Click Here


    Here is my HTML front end --
    HTML Code:
    <html>
    
    	<title> Welcome to Duff's Songs Inventory </title>
    	<h1></center><head> Congrats, now that you are here you are able to add songs to your inventory list!  </head></center></h1>
    <body>
    	<center>
    	<form action = "m5donovanCP7-2.php" method = "post">
    
    	<p><a href="m5donovanCP7-2.php">View List</a>  <a href = "m5donovanCP7-2.php">Sort By Name</a> <a href = "m5donovanCP7-2.php">Shuffle Songs</a>
    	<br />
    	<br />
    
    
    		<input type = "text" name = "song" size = "25">
    		<input type = "submit" value = "Add Song">
    	</form>
    	</center>
    
    
    </body>
    
    </html>
    Here is the PHP code: This has the area that should be accepting the new song and writing it to the text file, which it currently isn't doing
    PHP Code:
    <html>

        <title> Welcome to Duff's Songs Inventory </title>
        <h2><center><head> You are viewing this page because you have submitted a song to our list</head></center></h2>
    <body>

    <?php

    if (empty($_REQUEST['song']) {
        print 
    "<p>You have not entered a song, please use link below and enter a song</p>";
        die ();
    }






    <?
    php print ("{$_REQUEST['song']}"); ?> has been added to Duff'sSong list!







    <?php

    if (file_exists("Duff'sSongs.txt") && filesize ("Duff'sSongs.txt") ! =0) {
    }
    $file "Duffs'sSong.txt";
    $duffsHandle fopen($file'a+');
    $song = ("{$_REQUEST['song']}");
    fwrite = ($duffsHandle$song);
    fclose ($duffsHandle);

    ?>

    <p>You have add a song. </p> <br />

    <p> To go back to the main menu <a href = m5donovanCP7-2.html>Click Here</a> 


    </body>

    </html>

  2. #2
    Join Date
    Oct 2006
    Posts
    1,297
    I would code this:
    PHP Code:
    if (empty($_REQUEST['song']) { 
        print 
    "<p>You have not entered a song, please use link below and enter a song</p>"
        die (); 

    more like this:
    PHP Code:
    if(!isset($_POST['song'])
    || empty(
    $_POST['song']))

        print 
    "<p>You have not entered a song, please use link below and enter a song</p>"
        exit; 


  3. #3
    Join Date
    Sep 2006
    Posts
    69
    Okay, i'm still having problems. It isn't quitting out of the "IF" statement and continues on with the code.
    Also, I'm trying to have these songs that are added to a text file. I have created another program and usd text files just fine, however this one is giving me some major problems. Would someone look over the syntax to make sure it is correct. I've reviewed but can't find anything

    Here is what it gives me if I submit a song or just click on add song button:

    You are viewing this page because you have submitted a song to our list You have not entered a song, please use link below and enter a song

    "; exit; } ?> has been added to Duff'sSong list!

    To go back to the main menu Click Here



    Here is the "new" PHP Code:
    PHP Code:
    <html>

        <title> Welcome to Duff's Songs Inventory </title>
        <h2><center><head> You are viewing this page because you have submitted a song to our list</head></center></h2>
    <body>
    <?php
    if(!isset($_REQUEST['title'])
    || empty(
    $_REQUEST['title']))
    {
        print 
    "<p>You have not entered a song, please use link below and enter a song</p>";
        exit;


    ?>


    <?php print ("{$_REQUEST['title']}"); ?> has been added to Duff'sSong list!


    <?php

    $file 
    "Duffs'sSong.txt";
    $duffsHandle fopen($file'a+');
    $title = ("{$_REQUEST['title']}");
    fwrite = ($duffsHandle$title);
    fclose ($duffsHandle);

    ?>

    <p> To go back to the main menu <a href = m5donovanCP7-2.html>Click Here</a> 


    </body>

    </html>
    Last edited by duff2481; 11-19-2006 at 02:10 PM.

  4. #4
    Join Date
    Oct 2006
    Posts
    1,297
    Change your use of print to echo instead.
    See if that helps any.

  5. #5
    Join Date
    Sep 2006
    Posts
    69
    No, that is not the issue. I've always used print and for my class that is what is instructed. Not sure what is causing the problem.

  6. #6
    Join Date
    Sep 2006
    Posts
    69
    I think there is an issue with PHP services on this machine. I'm trying to run my other code and it isn't displaying the time and date.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles