promotion image of download ymail app

How can i insert and retrieve records in php.give me a simple way.?

3 Answers

  • Anonymous
    1 decade ago
    Favorite Answer
    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    Lets say you have the table below...


    forename Surname Address

    bob wilson 32 fake road

    mark christon 1 fake road

    to add a row you could do something like below...

    connect to the database


    $Conn = mysql_connect("localhost", "myuser", "mypassword");

    mysql_select_db("dbTest", $Conn);


    Now build your insert Query


    $sql = "INSERT INTO tblPerson (Forename, Surname, Address) VALUES ('mick', 'johnson', '12 fake avenue')";

    // Run the insert

    // Tell it what the query is and the connection

    mysql_query($sql, $Conn);


    To read...


    $sql = "select * from tblPerson"

    // Handle / pointer to the results if you will

    $rs = mysql_query($sql);

    // while $rw contains an array of a row, each time the loop runs

    // it will grab the next row of data, so 1st time it will be bob, second time mark when there are no more rows it will stop since $rw will be equal to null

    while (($rw = mysql_fetch_assoc($rs)) != null)


    echo $rw['Forename']; // would print the forename



    • Commenter avatarLogin to reply the answers
  • 1 decade ago

    execute the insert with mysql_query for example. the select is the same, but to iterate throught the results, look in for an example. Greets

    • Commenter avatarLogin to reply the answers
Still have questions? Get your answers by asking now.