Results 1 to 20 of 20

Hybrid View

  1. #1

    Can you help me? Im a newb.... Some PHP stuff here... You PHP-gurus click right here!

    Im making a form where peeps can go in and register that they want to participate in a course or something....

    I'm almoast done making the layout, code and stuff, but i want to close the registration when X has registred (lets say X = 20)
    Like if 20 have registred, you cannot register...

    I tried this:

    <?php
    $result = @mysql_query("SELECT * FROM course where id = 20");
    if (isset($result)) {
    echo("This course is full"); }
    ?>

    this is not working, but im a complete newb... so dont make fun of me

    (and please dont make the answer complex, the only thing i have read is "Build Your Own Database Driven Website Using PHP & MySQL
    (First 4 Chapters)")

    Can you please help me? I would really appreciate it!
    Thank you...

  2. #2
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    How about

    PHP Code:
    $result mysql_query("SELECT * FROM course"); 
    $recordcount mysql_num_rows($result);

    if (
    $recordcount >= 20) {
      echo (
    "This course is full");

    However for 'good' sql that is cross compatible you should really use something like the following (but it can be faster to use the above if you have already called the table course)

    PHP Code:
    $recordcount mysql_result(mysql_query("SELECT COUNT(id) FROM course"),0);

    if (
    $recordcount >= 20) {
      echo (
    "This course is full");


  3. #3
    You got to it before I did rich . Well done.

  4. #4
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    Rich why do you put a "0" at the end of the result function?

    Also amess you should look into a book called MySQL teach yourself in 21 days. it's not too bad, it helped me alot when I first started to learn SQL.

    it will show you simple to more advanced SQL queries.

    ISBN 0-672-31914-4

    Good luck, not sure how deep you are going to get with PHP and MySQL.
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  5. #5
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    It's the initial row number.

  6. #6
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    thanks never used that
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  7. #7
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    According to the PHP manual it's a required statement but I have to admit I don't use it either!

    mixed mysql_result ( resource result, int row [, mixed field])

  8. #8
    Thanks for the help, but I cant get it to work... Please take a look at my code....

    ________________________________________________

    <?


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

    $result = mysql_query("SELECT * FROM kurs2;");
    $recordcount = mysql_num_rows($result);
    if ($recordcount >= 20) {
    echo ("This course is full");
    }





    if ($meld == 1) {
    $dbcnx;
    @mysql_select_db("br");
    $sql = "INSERT INTO kurs2 (kurs, bransatt, avd, kunde, kommentar, kontakt, overn, grkurs, date) values
    ('$kurs',
    '$bransatt',
    '$avd',
    '$kunde',
    '$kommentarer',
    '$kontakt',
    '$overn',
    '$grkurs',
    CURDATE());";
    if (@mysql_query($sql)) {
    echo("<p>thank you</p>");
    } else {
    echo("<p>error: " .
    mysql_error() . "</p>");
    }
    }

    ?>

    ________________________________________________

  9. #9
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    What's your error message and what is going wrong with it? Is that a complete script as it doesn't appear to have anywhere defining what $meld is

    Additionally you have connected to the mysql server but not connected to a database, you need to add

    $dbsel = mysql_select_db($db, $dbcnx);
    if (!$dbsel) {
    print mysql_error();
    exit;
    }

    between your SQL statement and your connection routine.

  10. #10
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    In addtion what kind of fields are the following:

    $bransatt',
    '$avd',
    '$kunde',
    '$kommentarer',
    '$kontakt',
    '$overn',
    '$grkurs'

    if they contain any string/text/char array you should format it this way:

    '".$bransatt."', '".$avd."', '".$kunde."', '".$kommentarer."', '".$kontakt."', '".$overn."', '".$grkurs'" ....

    John
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  11. #11
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    I found to have errors doing the other way and find it to work better with the " "

    I could be wrong but it's just my exprience

    John
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  12. #12
    Thank you!! it worked... i have some work left though.

    But i have another question:
    What kind of format can you set a mysql-row?
    i know of text date time + but how can i make a multi-lined rows, f.ex. this forum...?

    Thanks again.-..

  13. #13

  14. #14
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    text field is nice.

    I have a GREAT front end for MySQL for windows. if you are interested let me know and I'll send you the prog.

    I learned alot from it and that's how I build all my database.

    It's easier for me to do it that way, even now I know the datatypes and how to do it CLI

    John
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  15. #15
    Yeah, im interrested!
    Please send the prog or link to download it

    Thank you...

    But when i format it as text, and someone enters some text in a textfield like this, the text just comes out as one line, depending on the tables width...
    how can i make it as i want?

  16. #16
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    you can use an PHP function called nl2br to format the text as the user entered it.

    echo nl2br (stripslashes($row->note));

    $row->note being your variable what ever that might be. In my case I pulled the variable from an SQL query.

    John

    john@inofficenetworks.com (email me to forward the file to you)
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

  17. #17
    i dont think you understood me...
    like
    this
    i
    am
    adding
    new
    lines....

    when i do that is my form the whole thing comes on one line and theres just spaces insted of new lines. i want there to be lines!

    hope you understand

  18. #18
    Join Date
    May 2002
    Location
    UK
    Posts
    2,997
    When you retrieve it from the database use the nl2br function! It'll put the carriage returns back in

  19. #19
    oh... ok then..

    thanx

  20. #20
    Join Date
    Aug 2002
    Location
    Long Island
    Posts
    427
    did it work for you?
    John Trovato
    In Office Networks, LLC
    Programmer, Cisco Network Engineer, Roofer, Biochemist, and Conductor.

Posting Permissions

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