Hello, I just started with PHP and MySQL. I want to make database similar to http://www.sharereactor.com/. So I made 4 tables.
1. Data (id, name, year, category, language, genre_id, duration, size, image_id, links_id)
2. Genre (id, genre)
3. Image (id, image url)
4. Links (id, name1, link1, name2, link2, name3, link3)

My question are:
1. Is it good table that I made?
2. The 4th table sometimes could have only one name and link, so would not need name2, link2, ... But sometimes it will use 2 names and links or more. So how to make 4th table with links?

Thaks in advance

    Make table 4

    data_id | id | name | link

    That wany you can have 0,1 or many links for any data id.

    Remove link_id from data table.

    hth

      BTW, can several data records have the same image or is it one data record per image?

      if it is always a unique image per data record, why not put image url in data record instead of image_id and lose image table

        Thaks for ideas πŸ™‚ I think it will be one link per image. So I use your advice and remove image table and store image link directly to DATA table.

        So I got a tables and relationship between it. No I need to start to program it.
        So here is another question: How to enter data into form? I need to use a form and put data into variables like $name and then send them to tables in database?
        1. Any ideas as for begining person how to make enter information form for DATA table for fields like image?
        2. How to get real name of image file from location in a disk?
        3. How to put data into 4th (now 3th) LINK table?
        3th table (data_id, id, name, link)

          Thanks for link, I studed it.
          I wrote my egsample from that guide, but it didn't work πŸ˜•
          Maybe you will see an error (then I press add genre url, nothing hapen).

          <?php
          include("dbinfo.inc.php");

          if (isset($addgenre)):
          ?>
          <form action="<?=$PHP_SELF?>" method="post">
          <P>
          Enter genre: <INPUT type="text" name="genrename"><BR>
          <INPUT type="submit" name="submitgenre" value="SUBMIT"> <INPUT type="reset">
          </P>
          </form>

          <?php
          else:
          $dbconx = @mysql_connect($mysql_host,$mysql_user,$mysql_password);
          if (!$dbconx) {
          echo( "<p>Unable to connect to the " . "database server at this time.<p>");
          exit();
          }
          if (! @mysql_select_db($my_db)) {
          echo( "<p>Unable to locate the database at this time.</p>");
          exit();
          }
          // if a genre has ben submitted, addd it to databse
          if ($submitgenre == "SUBMIT") {
          $sql = "INSERT INTO genre VALUES (,$genrename)";
          if (@($sql)){
          echo("<p>Genre has been added.</p>");
          } else {
          echo("<p>Error adding submitet genre: " .
          mysql_error() . "</p>");
          }
          }
          echo("<p> Here all genres in our table: </p>");
          $result = @("SELECT genre_name FROM genre");
          if (!$result) {
          echo("<p>Error performing query: " . mysql_error() . "</p>");
          exit();
          }

          while ($row = mysql_fetch_array($result) ) {
          echo("<p>" . $row["genre_name"] . "</p>"); }

          echo("<p> <a href='$PHP_SELF?addgenre=1'> Add a genre! </a> </p>");

          endif;
          ?>

            It looks as though you are assuming register_variable is ON whereas later versions of php now have it OFF by default. The will prevent variables being created automatically from posted data.

            Try

            if (isset($_POST['addgenre'])):

            also add

            $genrename = $POST['genrename'];
            $submitgenre = $
            POST['submitgenre'];

            before referncing those 2 variables.

            hth

              You need the '!'. (ie if not set)

              if (!isset($addgenre)):

                Yes, but its not that I wanted.

                I put all code without statement:
                if (isset($addgenre)): or
                if (isset($_POST["addgenre"])):

                and without $genrename = $POST["genrename"]; $submitgenre = $POST["submitgenre"];
                and without echo("<p> <a href='$PHP_SELF?addgenre=1'> Add a genre! </a> </p>"); at the end of code into new page - everything works fine.

                So th error is in echo("<p> <a href='$PHP_SELF?addgenre=1'> Add a genre! </a> </p>");
                All that I manage to think is addgenre don't get value 1 and then I look to it at statement if (isset($addgenre)): or
                if (isset($_POST["addgenre"])):

                it won't work.

                Any idea, why?

                  addgenre variable is sent directly from url using GET method, so i think you should use...

                  if (isset ($_GET['addgenre'])) :

                  instead.
                  When taking the values of the variables of the form, you should in fact use $_POST['variable'] as you have used that method to send them. (<form ... method="POST">)
                  hope it helps

                    Write a Reply...