SitePoint Sponsor

User Tag List

Results 1 to 21 of 21
  1. #1
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hello,

    I am new at this PHP/mySQL thing, but have come a long way with the helo of the SitePoint tutorial by Kevin. (Thanks Kevin!)

    I am going to have a page where you can download song samples (in mp3 and real audio form)....

    I would also like to increment a field in the table of the song that was chosen. (that way, I can see what is popular, or give a top 5 list...)

    ex:
    1) song 1 gets picked (real audio form)
    2) go to the db and add 1 to the counter field
    3) start the download of the file
    4) hopefully stay on the same page

    (I would like to be able to do everything while staying on the same song sample page)

    I have the page set up, but I am not sure how to go about after somebody SELECTS a song sample...Could somebody point me in a direction!

    My page is here:
    http://keithlubrant.com/samples/

    ALSO:
    I cannot remove that little orange line (ONLY IN NETSCAPE) under my .gifs....I added the border=0 to the image syntax....Is there a way to remove this??


    Thanks a bunch!
    Keith

  2. #2
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi there.

    What I would do is something like this :

    Code:
    <?php
    
    mysql_connect("xxx","xxx","xxx");
    mysql_select_db("xxx");
    $result=mysql_query("SELECT * from table");
    
    $numrows = mysql_num_rows($result);
    
    if ($numrows==0) {
    
    
    
    mysql_connect("xxx","xxx","xxx");
    mysql_select_db("xxx");
    mysql_query("INSERT INTO table SET count=1");
    
    header("Location: http://www.website.com/files/file.mp3");
    
    }
    
    
    else {
    
    mysql_connect("xxx","xxx","xxx");
    mysql_select_db("xxx");
    
    mysql_query("UPDATE xxx SET count=count+1");
    
    header("Location: http://www.website.com/files/file.mp3");
    
    }
    
    
    
    
    
    ?>
    I'm sure someone else can improve what I've given you there, but that is the raw basis for a script which basically does what you want.

    -J

  3. #3
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks a bunch James!
    Hmmm...so I looked up the header syntax and that can be used to take the browser to another page or to a file. So to experiment, I put it after the routine that adds the visitors information to my guestbook page....

    So that it will enter the data and then go back to the guestbook page

    The code is:

    if ("SUBMIT" == $submitmessage) {
    $sql = "INSERT INTO guestbook SET " .

    "name='$name', " .
    "city='$city', " .
    "state='$state', " .
    "country='$country', " .
    "message='$message', " .
    "date=curDATE()";
    }
    if (mysql_query($sql)) {
    header("Location: http://www.keithlubrant.com/guestbook");
    } else {
    echo ("<P><B>Error adding entry to the Guestbook: " .
    mysql_error() . "</B></P>");
    }


    ?>


    And here is the error information:

    Cannot add more header information - the header was already sent (header information may be added only before any output is generated from the script - check for text or whitespace outside PHP tags, or calls to functions that output text) in verify.php3 on line 170

    And line 170 is:
    header("Location: http://www.keithlubrant.com/guestbook");
    <Edited by klubrant on 12-16-2000 at 06:35 PM>

  4. #4
    SitePoint Wizard silver trophy Karl's Avatar
    Join Date
    Jul 1999
    Location
    Derbyshire, UK
    Posts
    4,411
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you have any text being sent to the browser e.g. print, echo etc. or anything before the opening <?(php) tags then the header will not work. You need to make sure that no text including spaces and line feeds has been sent to the browser.
    Karl Austin :: Profile :: KDA Web Services Ltd.
    Business Web Hosting :: Managed Dedicated Hosting
    Call 0800 542 9764 today and ask how we can help your business grow.

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok, after digging in the archives, I found this thread
    http://www.sitepointforums.com/showt...threadid=12357

    but, could somebody show me the correct way to use the header function....

    I have tried many and still get the same error.
    (I have cut out all the mumbo jumbo and just tried doing an insert data and go to page ...)

    code (and this is all that is in the .php3 file)
    <?php
    $dbcnx = @mysql_connect("xxxx", "xxxx", "xxxx");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the server at this time.</P>" );
    exit();
    }
    if (! @mysql_select_db("xxxx") ) {
    echo ("<P>Unable to locate the guestbook database.</P>");
    exit();
    }


    if ("SUBMIT" == $submitmessage) {
    $sql = "INSERT INTO guestbook SET " .

    "name='$name', " .
    "city='$city', " .
    "state='$state', " .
    "country='$country', " .
    "message='$message', " .
    "date=curDATE()";
    }


    if (mysql_query($sql)) {
    header("Location: http://www.keithlubrant.com/guestbook");
    }
    ?>


    Anybody see anything?

  6. #6
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This should work if it is the only thing in your script. If you have any "output" (and by that I mean characters etc printed on the screen, or white space) before the header code, then it will not work. It works like cookies in this way.

    J

  7. #7
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ok, I have to be doing something wrong!
    All I put in a temp page was this:

    <?php
    header("Location: http://www.keithlubrant.com/guestbook");
    ?>


    I also tried:

    <?php

    $dbcnx = @mysql_connect("xxxx", "xxxx", "xxxx");
    if (!$dbcnx) {
    echo( "<P>Unable to connect to the server at this time.</P>" );
    exit();
    }

    if (! @mysql_select_db("xxxx") ) {
    echo ("<P>Unable to locate the guestbook database.</P>");
    exit();
    }

    header("Location: http://www.keithlubrant.com/guestbook");
    ?>


    Nothing works.....Can anybody show me the light?!

    Thanks,
    Keith

  8. #8
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what was the error

  9. #9
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This was the error:

    Warning: Cannot add more header information - the header was already sent (header information may be added only before any output is
    generated from the script - check for text or whitespace outside PHP tags, or calls to functions that output text) in
    /home/keithlub/keithlubrant-www/working.php3 on line 2

    when I had:

    <?php
    header("Location: http://www.keithlubrant.com/guestbook");
    ?>

  10. #10
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have either

    a)white space

    or

    b)HTML / other characters

    before that code you have shown me. Remove that, and then try it.

    J

  11. #11
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes the following will produce the error

    Start of file


    <html>
    <?
    header("Location http://yoursite.com");

    Start of file

    <?
    header("Location http://yoursite.com");



    But this will not
    Start of file
    <?
    header("Location http://yoursite.com");


    Notice the difference between the first two and the third the first two either had blank lines or whitespace before the header call outside of the php tags or html
    Please don't PM me with questions.
    Use the forums, that is what they are here for.

  12. #12
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, I see what you guys are saying. My temp page is as follows:


    <?php
    header("Location http://www.yahoo.com");
    ?>

    The <?php starts at the VERY top of the page. I do get a different error..stating document contains no data...

    Let me try and understand this from a different angle...

    I have a database which contains the filename and a counter for each of the songs

    On my page, I have the table with songs displayed(by PHP)(see http://www.keithlubrant.com/samples)


    1) say i just hit the ALL I WANT TO BE mp3 icon

    2) I am now passing a variable called file that has the filename ALL_I_WANT_TO_BE.mp3

    3) I want to go to my table and increase the count for ALL I WANT TO BE by 1

    4) start downloading the song sample

    Maybe I am taking the wrong route. I was going to use Jame's idea, but I cannot get the header function to work (even just by itself!!!)

    Would I have to go to another page if somebody selected a sample? or can I do everything in the same page?

    Freddy,James and Karl....Thanks for trying to help me out on this one. For some reason, it's just not "getting upstairs!"

    How would you guys go about what I need to do?

    Thanks,
    Keith

  13. #13
    SitePoint Author Kevin Yank's Avatar
    Join Date
    Apr 2000
    Location
    Melbourne, Australia
    Posts
    2,571
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Now you're missing the colon:

    Code:
    header("Location: url");
                    ^
    Kevin Yank
    CTO, sitepoint.com
    I wrote: Simply JavaScript | BYO PHP/MySQL | Tech Times | Editize
    Baby’s got back—a hard back, that is: The Ultimate CSS Reference

  14. #14
    psycho
    Join Date
    May 2000
    Location
    London
    Posts
    283
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    What I would do is this :

    Change your the link to the song in the list you have generated by PHP to download.php3?ID=$row[ID] or whatever you have stored the ID var in.

    This way you can create a generic script to download a selected file.

    Next, when the user clicks on the link have this :

    <?php

    mysql_connect("xxx","xxx","xxx");
    mysql_select_db("xxx");
    mysql_query("UPDATE xxx SET count=count+1 WHERE ID = '$ID'");



    $result = mysql_query("SELECT filename FROM table WHERE ID = '$ID'");

    while ($row = mysql_fetch_array($result) ) {

    $filename = $row[filename]

    }

    header("Location: http://www.website.com/files/$filename");

    }








    ?>



  15. #15
    SitePoint Member
    Join Date
    Dec 2000
    Location
    Southampton UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    James, Klubrant: One thing, if there's only one file you don't need a while statement when you get your row and it's easier to check for an error with only one call, ie:

    if (!$row = mysql_fetch_array($result))
    {
    echo "Error, please contact us etc";
    }
    else
    {
    header("Location: ".$result['filename']);
    }

    Hope That Helps
    - Jamie

  16. #16
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are going to be 2 files (mp3 and real audio)...
    I got it to work, finally!!!!

    thanks to everyone for their help. I learned so much from this little fiasco (ya know to send TWO variables to a page, you use the AMPERSAND....that had me puzzled for a good 3 hours!!!)

    Anyway...thanks!
    Keith

  17. #17
    SitePoint Member
    Join Date
    Dec 2000
    Location
    Southampton UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Klubrant, glad to hear it works! Can I ask how you managed to get it to download two files at the same time, or did you do them seperately?
    - Jamie

  18. #18
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It was 2 separate files. The visitor had the option of hearing the song in MP3 format or Real Audio.

    Anybody have any suggestions for the orange line that is beneath the icons when viewing in Netscape? (4.73)

    I added the border=0 but to no avail
    (I am keeping this in the PHP forum because technically, it is done in the PHP code!)

    Thanks,
    Keith
    singer/songwriter...that's why I ask all the questions!
    www.keithlubrant.com

  19. #19
    SitePoint Member
    Join Date
    Dec 2000
    Location
    Southampton UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Keith,

    The line is because there is no '</A>' tag after the image to show where the link stops. Netscape sees the space after the <IMG> tag as part of the link and so underlines it, hence the line. When you put in the '</A>' make sure there's no gap between it and the image tag.

    Hope That Helps
    - Jamie

  20. #20
    SitePoint Enthusiast
    Join Date
    Jun 2000
    Location
    Turnersvill, NJ
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you the man....

    Thanks! That makes sense....You saved me from another 3 hour session

    -Keith


  21. #21
    SitePoint Member
    Join Date
    Dec 2000
    Location
    Southampton UK
    Posts
    8
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    No worries, I've been there myself
    - Jamie


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
  •