#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2004
    Location
    London
    Posts
    2
    Rep Power
    0

    Smile Editing table data in a web browser and return to mysql database


    Hello!
    For any of those who viewed it, i have sorted half of my previously posted query (5th FEB). So thanks for all your help. Extracting the relevant data from my sql database is now not an issue.

    I can produce the data in a table on my web browser.
    The issue now is how can i edit a particular column and then return back the values to the mysql database.

    e.g.

    3 columns

    StudentId
    StudentSurname
    Grade

    I require the grade column to be editable so recent grades can be included. A submit button can then be pressed and the resulting data is sent to the correct table in mysql.

    Any help would be greatfully appreciated as i think im gonna cry soon! Thanks!!!!!
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    411
    Rep Power
    15
    alright.. since I am bored I will make a 'sample' you can work off of.
    Code:
    file.php:
    switch($action)
    {
    case 'update' :
    //connect to db then run a query similar to this
    $query = mysql_query("UPDATE table SET StudentId='$_POST[id]', StudentSurname='$_POST[surname]', Grade='$_POST[grade]' WHERE StudentId='$_POST[id]'");
    break;
    
    default:
    $query = mysql_query("SELECT * FROM table WHERE StudentID=20");
    $id=mysql_result($query,0,StudentID);
    $surname=mysql_result$query,0,StudentSurname);
    $grade = mysql_result($query,0,Grade);
    
    // grabbing a single student's information
    print '<form method="post" action="file.php?action=update">';
    print 'StudentId <input type="text" value="'.$id.'" name="id"><br>';
    print 'Surname <input type="text" value="'.$surname.'" name="surname"><br>';
    print Grade <input type="text" value="'.$grade.'" name="grade"><br>';
    break;
    }
    Last edited by file cabinet; February 11th, 2004 at 08:26 AM.
  4. #3
  5. Learn logic, not PHP!
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Location
    Hong Kong SAR
    Posts
    1,006
    Rep Power
    16
    PHP Code:
    <?php
    if (!isset($_POST['submit']))
    {
        
    // Assume you have retrieved the row that contains the id, surname, and grade in $row.
        
    ?>
        <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
            <input type="text" name="id" value="<?=$row['StudentId']?>">
            <input type="text" name="surname" value="<?=$row['StudentSurname']?>">
            <input type="text" name="grade" value="<?=$row['Grade']?>">
            <input type="submit" name="submit" value="Submit">
        </form>
        <?php
    }
    else
    {
        
    $sql "update $table set StudentSurname='{$_POST['surname']}', Grade='{$_POST['grade']}' where StudentId='{$_POST['id']}'";
        
    // Update the DB here.
    }
    ?>
    EDIT: Oops... Just realized that a reply has been posted.
    Last edited by ninebirds; February 11th, 2004 at 08:29 AM.
    error_reporting(E_ALL) and echo($debug_message) may help to heal your headache.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2004
    Posts
    411
    Rep Power
    15
    Originally posted by ninebirds


    EDIT: Oops... Just realized that a reply has been posted.
    yeah but only minutes apartm, and with PHP, the more the merrier.

IMN logo majestic logo threadwatch logo seochat tools logo