$_post Error Help!

Discussion in 'PHP' started by Voimis, Oct 14, 2007.

  1. #1
    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? :eek:

    Thanks a lot!
     
    Voimis, Oct 14, 2007 IP
  2. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #2
    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 ;)
     
    theOtherOne, Oct 14, 2007 IP
  3. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    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 :confused:

    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

    :eek:
     
    Voimis, Oct 15, 2007 IP
  4. goldensea80

    goldensea80 Well-Known Member

    Messages:
    422
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    128
    #4
    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.
     
    goldensea80, Oct 15, 2007 IP
  5. theOtherOne

    theOtherOne Well-Known Member

    Messages:
    112
    Likes Received:
    4
    Best Answers:
    0
    Trophy Points:
    108
    #5
    Are your .txt-files actually writable? Try to comment the header() lines and see what errors you get
     
    theOtherOne, Oct 15, 2007 IP
  6. Invent

    Invent Peon

    Messages:
    109
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    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.
     
    Invent, Oct 15, 2007 IP
  7. Voimis

    Voimis Peon

    Messages:
    60
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    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!
     
    Voimis, Oct 16, 2007 IP
  8. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #8
    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
     
    Lordy, Oct 16, 2007 IP