PHP SELECT - MYSQL Database question

Discussion in 'PHP' started by Cain Fleming, Dec 21, 2010.

  1. #1
    Hi,

    I have recently just started learning about MYSQL/PHP and I need some guidance.

    I have created a form, so that once a user submits the form the data is stored on a MYSQL database.

    My form submits an event. When the user submits a new event through my form, I want a separate web page to be created for each new form entry.

    How do I go about doing this?

    Hopefully this makes sense.

    Thanks,

    Cain
     
    Cain Fleming, Dec 21, 2010 IP
  2. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #2
    I don't see the use of creating a separate web page for each event , instead you should create a php page that will read an event from the database.
    For example , event.php?id=1 will show the info for the event that has the id = 1.

    Example code :
    
    <?php
    $db = mysql_connect("host","username","password");
    mysql_select_db("database_name",$db);
    
    $result = mysql_query("SELECT * FROM events_table WHERE id = '".$_GET['id']."' LIMIT 1");
    if(mysql_num_rows($result) == 1)
    {
    $row = mysql_fetch_array($result);
    
    //echo the info you need for that event : echo $row['name'] etc.
    }
    ?>
    
    PHP:
    Don't forget to sanitize the data read from outside the file ($_GET,$_POST) before querying mysql ( look here PHP MySQL Class , concentrate on the cleanQuery($input) function.
     
    tvoodoo, Dec 21, 2010 IP
  3. Cain Fleming

    Cain Fleming Peon

    Messages:
    29
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Thanks, the theory behind this makes sense.

    However what is the purpose of sanitizing the data?
     
    Cain Fleming, Dec 21, 2010 IP
  4. tvoodoo

    tvoodoo Active Member

    Messages:
    239
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    53
    #4
    Preventing SQL Injection.
     
    tvoodoo, Dec 21, 2010 IP