/    Sign up×
Community /Pin to ProfileBookmark

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 —

[code=html]
<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>

[/code]

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

[code=php]
<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>

[/code]

to post a comment
PHP

5 Comments(s)

Copy linkTweet thisAlerts:
@so_is_thisNov 19.2006 — I would code this:
[code=php]
if (empty($_REQUEST['song']) {
print "<p>You have not entered a song, please use link below and enter a song</p>";
die ();
}[/code]


more like this:
[code=php]
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;
}[/code]
Copy linkTweet thisAlerts:
@duff2481authorNov 19.2006 — 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:

[B] 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 [/B]



Here is the "new" PHP Code:
[code=php]
<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>
[/code]
Copy linkTweet thisAlerts:
@so_is_thisNov 19.2006 — Change your use of [B]print[/B] to [B]echo[/B] instead.

See if that helps any.
Copy linkTweet thisAlerts:
@duff2481authorNov 19.2006 — 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.
Copy linkTweet thisAlerts:
@duff2481authorNov 19.2006 — 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.
×

Success!

Help @duff2481 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.16,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...