Hi I have code which doesn´t work. It should make me shirt list of my music shirts. And here is the code: $artist = $_POST['artist']; $name = $_POST['name']; $license = $_POST['license']; $row = $artist . " - " . $name; if (isset($_REQUEST['license']) || $license == 'official') { $adding_band = fopen("entries/shirt_official_bandlist.txt", "a"); fwrite($adding_band, "\n" . $artist); fclose($adding_band); $adding_record = fopen("entries/shirtlist_official.txt","a"); fwrite($adding_record, "\n" . $row); fclose($adding_record); header('Location: shirtlist.php'); } if (isset($_REQUEST['license']) || $license == 'unofficial') { $adding_band = fopen("entries/shirt_unofficial_bandlist.txt", "a"); fwrite($adding_band, "\n" . $artist); fclose($adding_band); $adding_record = fopen("entries/shirtlist_unofficial.txt","a"); fwrite($adding_record, "\n" . $row); fclose($adding_record); header('Location: shirtlist.php'); } PHP: It should post shirts with "official" and "unofficial" tags to different .txt files! It doesn´t post anything to .txt files! What I have to change? Thanks a lot!
Hi, what is the form that submits data to your script? By the way: I think in the following line: if (isset($_REQUEST['license']) || $license == 'official') { you should replace || by &&. And it would be better if you decided whether you use REQUEST or POST to access the variables! Otherwise you might experience some unexpected behaviour
Form is like this: <form action="adding_shirt.php" method="post"> Artist:<br /><input type="text" name="artist" maxlength="100" size="40"><br /> Name:<br /><input type="text" name="name" maxlength="100" size="40"><br /> License:<br /><input type="text" name="license" maxlength="100" size="40"><br /><br /><br /> <input type="submit" value="Add shirt"> </form> PHP: But it doesn´t work, it doesn´t post anything to .txt files Which kind of string I need make to adding_shirt.php? I want it works like that: If I write "official" to form place 'license' it should post the data to shirtlist_official.txt and if I write "unofficial" to form place 'license' it post the data to shirtlist_unofficial.txt
Is there any error or warning message? Some tips: You can try the debug code like this: echo "<br>receive: $artist : $name : $license"; To get rid of warning message, You can use: $artist=isset($_POST[' artist']) ? $_POST[' artist'] : ''; You don't need to use $_REQUEST in the condition.
That wouldn't make a difference as any error would count as outputted data and so the header wouldn't be sent. I'm not sure why it isn't working, I'll have a quick think and get back to you.
It works now, I forget give the chmod rights to .txt files. But it posts the data ALWAYS to official list even if I write to form "unofficial"... Thanks!
probably because you have your code as if (isset($_REQUEST['license']) || $license == 'official') PHP: unless you already changed it. it should be && instead of || as 2nd poster stated