Php help
Results 1 to 9 of 9

Thread: Php help

  1. #1
    Junior Member
    Join Date
    Dec 2014
    Posts
    8

    Php help

    Hello..i am new here and i am new to php...i have several problems that i would like an answer for..

    First how to include a css file in a php file..i have tried the regular call like in html but it didnt work.

    Also which is more important than the first is

    I have a a project to make which is a gym website..i have a problem on making a booking page, to book a class i need the member id and class number from different tables classes and members, i created page with a form first field for member id second feild is for class number..but how can i make sure the class is NOT full and the member is exists in the members table, any idea? It may sound dumb to you but yeah i am learning

  2. #2
    Senior Member
    Join Date
    Mar 2009
    Posts
    820
    You can use the include_once() or require_once() constructs to bring in a CSS file into a PHP file.

    As for your other problems, can you provide some code for us to look at?
    Declare variables, not war.

  3. #3
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,593
    Quote Originally Posted by meme
    i have tried the regular call like in html but it didnt work.
    It should work. What did you try? The point is that the output of your PHP script will be a HTML document (in this case), and hence that inclusion of the stylesheet will happen in the output.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  4. #4
    Junior Member
    Join Date
    Dec 2014
    Posts
    8
    This is the call I used>>>

    PHP Code:
     <head>
    <link rel="stylesheet" href="style.css" type="text/css">
     </head>

      <body>

    <?php
    $username 
    "root";
    $password "";
    $hostname "localhost";
    As for the other problem..here is my code..it does the insertion but I need to make sure its actually a true member_id and also make sure the class is available and not full, I have a capacity column in the class table:

    PHP Code:
    <form action='#' method='post'>
     <table cellspacing='5' align='center' border ='1'>
     <tr><td>Member_ID:</td><td><input type='text' name='member_ID'/></td></tr>
     <tr><td>Class number:</td><td><input type='txt' name='Class_no'/></td></tr>
     <tr><td></td><td><input type='submit' name='Book' value='Book'/></td></tr>
     </table>
     </form>

     <?php

    $username 
    "root";
    $password "";
    $database"Mygym";

      
    $member_ID=$_POST['member_ID'];
      
    $class_no=$_POST['Class_no'];


    mysql_connect("localhost",$username,$password);

    @
    mysql_select_db($database) or die ("Unable to select database");



     
        
    $query="insert into book values ('$member_ID', '$class_no') ";
        
    mysql_query($query);
    mysql_close();
    ?>
    Last edited by bradgrafelman; 12-19-2014 at 09:10 AM. Reason: bbcode tags added

  5. #5
    PHP Witch laserlight's Avatar
    Join Date
    Apr 2003
    Location
    Singapore
    Posts
    13,593
    Please post code snippets containing PHP code within [php][/php] bbcode tags.

    Concerning MySQL: the legacy MySQL extension is deprecated as of PHP 5.5. You should use the MySQLi extension or the PDO extension instead.
    Use Bazaar for your version control system
    Read the PHP Spellbook
    Learn How To Ask Questions The Smart Way

  6. #6
    Settled 4 red convertible dalecosp's Avatar
    Join Date
    Jul 2002
    Location
    Accelerating Windows at 9.81 m/s....
    Posts
    7,730
    Your second snippet is interesting. Normally, you would want to check that the form is posted before doing an insert. I've done that, and converted your DB calls to mysqli_* and made a few comments you might wish to think about/investigate:

    PHP Code:
    <?php

    if (!$_POST) {

    ?>
    <form action='#' method='post'> 
     <table cellspacing='5' align='center' border ='1'> 
     <tr><td>Member_ID:</td><td><input type='text' name='member_ID'/></td></tr> 
     <tr><td>Class number:</td><td><input type='txt' name='Class_no'/></td></tr> 
     <tr><td></td><td><input type='submit' name='Book' value='Book'/></td></tr> 
     </table> 
     </form> 

    <?php 

    } else {

       
    $username "root"
       
    $password ""
       
    $database"Mygym"

       
    $member_ID=$_POST['member_ID']; 
       
    $class_no=$_POST['Class_no']; 

       
    // You probably should do some checking on the above.  For example, should the member_ID be numeric?
       // What if someone puts an word in there?  An *evil* SQL statement in there?  If both of these are numeric,
       // the solution *might* be as simple as checking with intval() and an integer, or perhaps with is_numeric().

       
    $db_conn mysqli_connect("localhost",$username,$password,$database); 

       if (!
    $db_conn) { //problem with DB connection or selection

          
    die("DB Problem"); //much better would be a legitimate error-handling routine ;-)

       
    }

       
    $query="insert into book values ('$member_ID', '$class_no') "
         
       
    mysqli_query($db_conn,$query); //once again, you're not testing for success.  Should your program
                         //give the user some feedback if the query fails?  What about a success message?

       
    mysqli_close($db_conn); 

    }
    ?>
    /!!\ mysql_ is deprecated --- don't use it! Tell your hosting company you will switch if they don't upgrade! /!!!\ ereg() is deprecated --- don't use it!

    dalecosp "God doesn't play dice." --- Einstein "Perl is hardly a paragon of beautiful syntax." --- Weedpacket

    Getting Help at All --- Collected Solutions to Common Problems --- Debugging 101 --- Unanswered Posts --- OMBE: Office Machines, Business Equipment

  7. #7
    Junior Member
    Join Date
    Dec 2014
    Posts
    8
    I am a student and this is what we learned, I don't know if we are able to switch , we only took a class on php and now she wants us to build a website, so I am self learning, I don't know much about php and I find it hard to learn, I know what you mean with all the validation but am not sure how to do it using php, my program should allow user to know if they already have booked that class, or not..but yeah I don't know how to do it, I think I am a pre-newbie now, feel so stupid :/

  8. #8
    Senior Member
    Join Date
    Mar 2009
    Posts
    820
    Quote Originally Posted by meme View Post
    I think I am a pre-newbie now, feel so stupid :/
    Don't feel stupid. No one here was born with his/her PHP knowledge; it was all learned through experience. You'll get there.

    When I was taught PHP for the first time in college the professor taught us to use addslashes() and stripslashes() to sanitize database queries. It was only later I learned that was a very bad approach (and doesn't make your queries safe at all).
    Declare variables, not war.

  9. #9
    Senior Member
    Join Date
    Apr 2003
    Location
    Silver Lake
    Posts
    4,938
    Self-learning is really the norm I think. I received a degree on computer science from a very prestigious university but didn't really know how to code when I graduated. I definitely didn't know a line of PHP. Don't feel stupid. Think about your problem, look for answers, ask questions, and then think about the answers you get. You'll understand eventually.
    IMPORTANT: STOP using the mysql extension. Use mysqli or pdo instead.
    World War One happened 100 years ago. Visit Old Grey Horror for the agony and irony.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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