Inserting data

Discussion in 'PHP' started by Sipifi, Aug 28, 2009.

  1. #1
    Hey all,

    I posted in PHP quite a few times already :) I have a very very low knowledge of php.

    Ok So i started using the php login v2 script on my website (a website where friends and family can add pictures etc... nothing important)

    The script has a table "users" which holds their basic information like username, password, website etc...

    Now i would like the users on my site have the ability to store favorite links private or public.

    I already created a new table that would hold: link name, description, private, id (take the user id from the current session?) and url. So now i would have to connect to the database, get the ID from the session and have a form that adds everything to that specific table right? But how? Could anyone be so kind to help me out?
     
    Sipifi, Aug 28, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Just look up some basic tutorials that take you through creating a blog or something. This is not something that we can just explain in a few steps.
     
    premiumscripts, Aug 29, 2009 IP
  3. EricBruggema

    EricBruggema Well-Known Member

    Messages:
    1,740
    Likes Received:
    28
    Best Answers:
    13
    Trophy Points:
    175
    #3
    Indeed premiuscripts; this is not telling you what to do but writing your script.

    Tell us exactly what you already did? show us your code.. and tell us what you want and where you think you got wrong!
     
    EricBruggema, Aug 31, 2009 IP
  4. vomers

    vomers Peon

    Messages:
    13
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    This is not the code you need, but shows an example of inserting data into a database from a form.

    ================== start of code===================
    <?php
    $con = mysql_connect("localhost","peter","abc123");
    if (!$con)
    {
    die('Could not connect: ' . mysql_error());
    }

    mysql_select_db("my_db", $con);

    $sql="INSERT INTO Persons (FirstName, LastName, Age)
    VALUES
    ('$_POST[firstname]','$_POST[lastname]','$_POST[age]')";

    if (!mysql_query($sql,$con))
    {
    die('Error: ' . mysql_error());
    }
    echo "1 record added";

    mysql_close($con)
    ?>
    ========================end of code=============

    ======================start of form=================
    <html>
    <body>

    <form action="insert.php" method="post">
    Firstname: <input type="text" name="firstname" />
    Lastname: <input type="text" name="lastname" />
    Age: <input type="text" name="age" />
    <input type="submit" />
    </form>

    </body>
    </html>
    ====================end of form============

    Example of how to get a session variable value

    ===================start of code==============
    session_start();
    $_SESSION['views'] = 1; // store session data
    echo "Pageviews = ". $_SESSION['views']; //retrieve data

    ===================end of code=====================

    I hope this helps if not you can find tutorials online or you may want to hire a freelancer to get this going or give it a try and then post what you have.
     
    vomers, Aug 31, 2009 IP