how to edit mysql database using php

Discussion in 'PHP' started by babyphp, Jun 9, 2008.

  1. #1
    how can i add edit to this code i want to to be albe to edit the databse as this page only view my database


    <?php
    require ("dbconnection.inc.php");
    connect();



    $search = $_POST["search"];$result = mysql_query("SELECT * FROM Businesses WHERE BusinessID
    LIKE '%$search%' OR CompanyName
    LIKE '%$search%' OR TradingName
    LIKE '%$search%' OR BusinessTypeID
    LIKE '%$search%' OR NumberOfSites
    LIKE '%$search%'OR NumberofEmployees
    LIKE '%$search%'OR CompanyVATNumber
    LIKE '%$search%'OR CompanyRegistrationNumber
    LIKE '%$search%'OR RegisteredAddressID
    LIKE '%$search%'OR YearEstablished
    LIKE '%$search%' OR NatureOfBusiness
    LIKE '%$search%'");


    echo "<table width=700 border=1>";


    echo "<tr bgcolor=ffffff align=middle font-size=50>


    <th>BusinessID</th>
    <th>CompanyName</th>
    <th>TradingName</th>
    <th>BusinessTypeID</th>
    <th>NumberOfSites</th>
    <th>NumberofEmployees</th>
    <th>CompanyVATNumber</th>
    <th>CompanyRegistrationNumber</th>
    <th>RegisteredAddressID</th>
    <th>YearEstablished</th>
    <th>NatureOfBusiness</th>


    </tr>";




    while($row=mysql_fetch_array($result))
    {

    $BusinessID=$row["BusinessID"];
    $CompanyName=$row["CompanyName"];
    $TradingName=$row["TradingName"];
    $BusinessTypeID=$row["BusinessTypeID"];
    $NumberOfSites=$row["NumberOfSites"];
    $NumberofEmployees=$row["NumberofEmployees"];
    $CompanyVATNumber=$row["CompanyVATNumber"];
    $CompanyRegistrationNumber=$row["CompanyRegistrationNumber"];
    $RegisteredAddressID=$row["RegisteredAddressID"];
    $YearEstablished=$row["YearEstablished"];
    $NatureOfBusiness=$row["NatureOfBusiness"];


    echo "<tr><td><a href='example.php?BusinessID=$BusinessID'>$BusinessID</a></td><td>" . $CompanyName . "</td><td>" . $TradingName . "</td><td>" . $BusinessTypeID . "</td><td>" . $NumberOfSites . "</td><td>" . $NumberofEmployees . "</td><td>" . $CompanyVATNumber . "</td><td>" . $CompanyRegistrationNumber . "</td><td>" . $RegisteredAddressID . "</td><td>" . $YearEstablished . "</td><td>" . $NatureOfBusiness . "</td></tr>" ;
    }echo "
    </table>";?>


    </p><p>&nbsp;</p></body></html>
     
    babyphp, Jun 9, 2008 IP
  2. alemcherry

    alemcherry Guest

    Best Answers:
    0
    #2
    These are the basics. The steps would be:

    1. Query the table as you do and make it appear in a form with editable fields by simply using the right HTML tags around the values. or you can simply put an edit link at the end of each row and generate the editable form on next page.
    2. When the user post the edited value, read it and update the database. This can be same or another php page. You may have to send the ID or somethign as a hidden field.

    You can actually refer some simple tutorail, there are tons of them available on net.
     
    alemcherry, Jun 9, 2008 IP
  3. Lordo

    Lordo Well-Known Member

    Messages:
    2,082
    Likes Received:
    58
    Best Answers:
    0
    Trophy Points:
    190
    #3
    Yes that is what you are up to.

    You will need $_GET, $_POST and mysql's UPDATE syntax.
     
    Lordo, Jun 9, 2008 IP
  4. sangpo

    sangpo Peon

    Messages:
    8
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Dear Sarakh Sir,

    Thank you very much for your prompt resppnse. Now with code you have forward, I can display the records,. Since I am beginner, I cannot add mode codes for invoking the eaditable field. Could you please send me code for that too.

    Thank you
     
    sangpo, Oct 22, 2012 IP
  5. Gemba

    Gemba Member

    Messages:
    36
    Likes Received:
    2
    Best Answers:
    1
    Trophy Points:
    25
    #5
    Don't forget to escape the input! The $search variable needs to be enclosed with mysql_escape_string
     
    Gemba, Oct 22, 2012 IP