How to edit items from SQL table in a html form

Swaggots

Member
Sep 22, 2013
98
18
So i'm designing a sort of CMS for retro owners that will allow them to list rare values and such, demo can be seen .

I've successfully been able to add values form a html form in the backend into the SQL table and output them in a html table on the homepage. The problem i'm having is if a manager wants to edit the value of a rare, how would I make it so the data that is stored in that rare's sql row will show into the html form so that he can edit it and re-add it to the sql table.

If you could possibly link me to a tutorial/article that explains this i'd be grateful, since all my google searches have turned up with nothing.

Thanks
 

Markshall

Русский Стандарт
Contributor
Dec 18, 2010
2,637
2,389
You need to refer to the specific ID of that item of furni and SELECT the information you need from the row then echo it out into the HTML form, then use the key in SQL to submit the changed data.

I hate spoon feeding but I'll show you a quick example:

So here, you would go to a link such as boonrares.site88.net/admin/edit.php?furniid=34 and it would grab information from the furni item with an ID of 34 in your database.
PHP:
<?php
$FurniID = (int)$_GET['furniid'];

$Furni = $db->query("SELECT * FROM `furni` WHERE `FurniID` = '{$FurniID}'");
if ($Furni->num_rows > 0) {
    $FurniRow = $Furni->fetch_array();
    echo '<form action="post">
        Name: <input type="text" name="name" id="name" value="' . $FurniRow['Name'] . '" /><br />
        Cost: <input type="text" name="cost" id="cost" value="' . $FurniRow['Cost'] . '" /><br /><br />
      
        <input type="submit" name="save" value="Save changes" />
    </form>';
} else {
    echo 'This furni item doesn\'t exist in our database.';
}
 
Last edited:

Users who are viewing this thread

Top