few basic php mysql questions

Discussion in 'PHP' started by phpwreker, Oct 28, 2012.

  1. #1
    [​IMG]

    first of all i need to understand what a row is in a table

    i know that it can have a variable name , variable value in the table


    could someone please explain it in simpler terms ?

    thanks
     
    phpwreker, Oct 28, 2012 IP
  2. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #2
    A "row" is the non-programmer's word for "record".

    Think of an Excel spreadsheet. A record (or row) in a database is a row in a spreadsheet. A field is a column in the spreadsheet. (So every record has the same fields, but not every record has the same value for the same field.)

    The fields have names and values, just as the columns in the spreadsheet have names (the first row usually has the name of the column) and values.
     
    Rukbat, Oct 28, 2012 IP
  3. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #3
    [​IMG]


    i am trying to understand this from a programmers point of view

    you know a table where id part which is set to auto increment


    [​IMG]

    i think i need to understand what a row , rows and group of rows means in a straight line means ..

    is it called an array of rows ?

    array of records ?

    and the primary key becoming the unique identifier for the rows

    right ?
     
    Last edited: Oct 28, 2012
    phpwreker, Oct 28, 2012 IP
  4. matt_62

    matt_62 Prominent Member

    Messages:
    1,827
    Likes Received:
    515
    Best Answers:
    14
    Trophy Points:
    350
    #4
    What is the importance of the snippet you have provided? I was uncertain if you wanted the snippet explained or not.

    In your snippet the tags "<td>" is for table data.
    There is more info here: http://www.w3schools.com/html/html_tables.asp
    SO to have a table, you have to open with <table> then you need a row, so thats <tr> then the actual data goes into a tag called <td>.

    i would have:
    <table> (opening table tag)
    <tr> (opening table row tag
    <td> (table data tag)
    Testing (content to appear goes here)
    </td> (close the table data tag)
    <td> (table data tag
    Testing2 (more content to appear goes here)
    </td> (close the table data tag)
    </tr> (close the row if your finished)
    </table> (close the table if you have no more rows)

    But those tags only affect what you see on the screen. They are HTML tags, NOT php / sql tags.

    I am not sure if i have been of much use, if you want to, supply with a larger code segment, or the exact code your having trouble with understanding or modifying and I can see if i can help further.
     
    matt_62, Oct 28, 2012 IP
  5. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #5
    what is that type="hidden" for ?
     
    phpwreker, Oct 28, 2012 IP
  6. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #6
    It is what it says, hidden. It will not be visible on the page. This is generally used for passing values through a form that has no relevance to the user but is important for the PHP code.

    For example, if the form is a register form, you could output the date in a hidden textfield and pass that through with the rest of the form. This is a basic example, but in the real-world you wouldn't need to hide a registered date as you would use the <?php $date();?> function in the actual PHP file to insert a date/time.
     
    scottlpool2003, Oct 29, 2012 IP
  7. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #7
    ok .. thanks .. but since i am a noob .. i am trying to understand these concepts in terms of three things ...

    variable name

    variable value

    and variable name in the table

    [​IMG]

    i think thats how the form should really look like .. right ?

    i think thats what the form really want to do .. but hides it from the user ..
     
    phpwreker, Oct 29, 2012 IP
  8. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #8
    That's correct.

    Your form would look like:

    <form method="post" action="submitform.php"> (method is how you want to handle your form. Post will post it within the browser whereas GET will send the form via the address bar.)
    
    <input type="text" name="name" value="Please enter your name"><br />
    <input type="password" name="password">
    <input type="submit">
    
    
    HTML:
    Then to pass these details to a new page (your form processing page) you would have something like:

    submitform.php
    
    <?php
    $name = $_POST['name'];
    $password = $_POST['password'];
    
    //Now we can do things with the passed variables such as enter into the database
    
    $con = mysql_connect("localhost","username","password");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    
    mysql_select_db("my_db", $con);
    
    mysql_query("INSERT INTO users (id, username, password)
    VALUES ('', '$name',$password)");
    
    PHP:
    Now what may confuse you there is that we're entering an ID into the database, but the ID is not declared anywhere. This is because in your database, the ID field will be 'auto increment' meaning that every new row that is inserted will automatically be assigned an ID. So with the above, if this is the first row in the database, the ID will be 1, the next one being 2 etc.
     
    scottlpool2003, Oct 29, 2012 IP
  9. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #9
     
    Rukbat, Oct 29, 2012 IP
  10. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #10
    its sort of nice to see how some codes work ... how html php and mysql works together ...

    [​IMG]


    from electrons [​IMG] to binary [​IMG]
     
    Last edited: Oct 30, 2012
    phpwreker, Oct 30, 2012 IP
  11. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #11
    OOPS
     mysql_query("INSERT INTO users (username, password) VALUES ('$name','$password');"); 
    PHP:
     
    Rukbat, Oct 30, 2012 IP
  12. phpwreker

    phpwreker Greenhorn

    Messages:
    67
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    16
    #12
    Last edited: Oct 30, 2012
    phpwreker, Oct 30, 2012 IP
  13. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #13
    There shouldn't be tutorials on PHP and MySQL, there should be (and are) tutorials on PHP, tutorials on SQL (among others) and tutorials on MySQL. They're 3 different subjects and you'll need (at least) 3 different tutorials. Playing with an interactive "PHP/MySQL tutorial" won't actually teach you anything.

    (And if you don't already know programming, learn that first. Learning programming languages doesn't teach you how to use them - you have to learn that before you learn individual languages like PHP and SQL.)
     
    Rukbat, Oct 30, 2012 IP
  14. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #14
    Furthermore:

     mysql_query("INSERT INTO users (username, password) VALUES ('$username','$password');"); 
    PHP:
     
    scottlpool2003, Oct 31, 2012 IP
  15. Rukbat

    Rukbat Well-Known Member

    Messages:
    2,908
    Likes Received:
    37
    Best Answers:
    51
    Trophy Points:
    125
    #15
    That depends on the name of the variable you use. The variable doesn't have to have the same name as the field. $name for the user name works just as well as $username.
     
    Rukbat, Oct 31, 2012 IP
  16. Overy1970

    Overy1970 Greenhorn

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #16
    How can i found php video tutorial on internet
     
    Overy1970, Oct 31, 2012 IP