简体   繁体   中英

Editing database in option tag with PHP

AUTHORS

<select name="author" >
    <?php
    $res = getAuthor();
    while ($row = mysql_fetch_array($res)) {
        ?>
        <option value="<?php echo $row['author_ID']; ?>"><?php echo $row['author_name']; ?></option>
    <?php } ?>
</select>

AUTHORS FUNCTION()

function editArticle()
{
$id = $_GET['editArticle'];
        $title = ($_POST['pTitle']);
        $post = ($_POST['tArea']);
        $date = ($_POST['date']);
        $author = ($_POST['author_name']);
        $url = mysql_real_escape_string($_POST['url']);
        $sum = addslashes($_POST['summary']);
        $col = $_POST['column_name'];
        if (isset($title) && isset($post))
{
mysql_query("update `articles` set title='$title', author_ID='$author', post='$post', 
        date = '$date', url = '$url', summary = '$sum', col_name = '$col' where article_ID = '$id' ") or
        die(mysql_error());
}

}

MAIN PROBLEM:

This is just an example of what I want the outcome to be.

I have this table where database is shown:

eg:
NAME:   SEX:
carlo   male         
-(btn)edit|dete

When I press edit, it goes to the edit page and it should look like this

NAME: carlo
SEX: <option >male</option>
     <option >female</option>

      (btn)UPDATE

but when it goes to the edit page, there are no values to be edited. Just blank text areas, and my "Sex" text ares is in option tag, so there are 2 type to choose from, so how can I get the value MALE from the database into the edit page?

So how do I make it so that when I go to edit the page, the dropdown is already selected to the item which it was when I added it? (In other words if they selected male in the add page, male will be automatically selected in the edit page).

选择框的名称为作者,因此在保存数据时必须为$_POST['author']而非$_POST['author_name']

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM