0

こんにちは、初めてこれを行います。基本的に、データベースからテキストボックスを再作成する方法についてかなり混乱しています。

私の現在の問題は、基本的にデータベース「USER」と「STATISTICS」に2つのテーブルがあることです。現在機能しているのは、私のコードが「USER」テーブルの「User_ID」の値を検索し、ドロップダウンリストに値を入力していることです。

そこから欲しいのは、「User_ID」EG「goal_scored」、「assist」、「clean_sheets」などを検索するデータベースからの値に対応するテキストフィールドを入力することです.

さまざまな質問を調べましたが、探しているものが見つかりません。

<?php
$link = mysql_connect("localhost","root","");
mysql_select_db("f_club",$link);
$sql = "SELECT * FROM user ";
$aResult = mysql_query($sql);

?>

<html>
<body>
<title>forms</title>
<link rel="stylesheet" type="text/css" href="css/global.css" />
</head>
<body>
<div id="container">

<form action="update.php" method="post">
<h1>Enter User Details</h1>
<h2>
<p> <label for="User_ID"> User ID: </label> <select id="User_ID" id="User_ID" name="User_ID" >
   <br> <option value="">Select</option></br>
    <?php
        $sid1 = $_REQUEST['User_ID'];

        while($rows=mysql_fetch_array($aResult,MYSQL_ASSOC))
        {

        $User_ID = $rows['User_ID'];
        if($sid1 == $id)
        {
        $chkselect = 'selected';

        }
        else
        {
        $chkselect ='';
        }
        ?>
        <option value="<?php echo  $id;?>"<?php echo $chkselect;?>>
        <?php echo $User_ID;?></option>
        <?php }
        ?>
        I had to put this in because everytime I have text field under the User_ID it goes next to it and cuts it off :S


         <p><label for="null"> null: </label><input type="text" name="null" /></p>
    <p><label for="goal_scored">Goal Scored: </label><input type="text" name="Goal_Scored" /></p>
    <p><label for="assist">assist: </label><input type="text" name="assist"  /></p>
    <p><label for="clean_sheets">clean sheets: </label><input type="text" name="clean_sheets" /></p>
    <p><label for="yellow_card">yellow card: </label><input type="text" name="yellow_card" /></p>
    <p><label for="red_card">red card: </label><input type="text" name="red_card" /></p>

    <p><input type="submit" name="submit" value="Update" /></p></h2>
</form>
</div>
</body>
</html>

誰かが次の段階に進む方法を理解するのを手伝ってくれるなら、感謝します x

4

1 に答える 1

0

AJAX のような複雑なことに時間を費やすよりも、user.php?id=1.

(あなたのuser.phpような)ファイルを作成し、id設定されている場合(if isset($_GET['id']))データベースからそのユーザーを選択します(もちろん、入力をサニタイズした後)(もちろん、ユーザーごとselect * from users where id = $idにあると仮定します)。id

は引き続き使用できますが<select>、忘れずに で閉じて</select>ください。次のような結果になる可能性があります。

<form method="get">
  <label for="user">Select user:</label>
  <select name="id" id="user">
    <option value="1">User 1</option>
    ...
  </select>
  <submit name="submit" value="Select user" />
</form>

これは現在のページに送信?id=<id>され、フォームに入力できます。そのデータをさらに編集したい場合は、次のようなコードでデータが入力された新しいフォームを作成し、<input type="text" name="goal_scored" value="<?php echo $result['goal_scored']; ?>" />データベースmethod="post"をリッスンしisset($_POST['submit'])て更新してください。

例:

<?php
// init
// Use mysqli_ instead, mysql_ is deprecated
$result = mysqli_query($link, "SELECT id, name FROM users");
// Create our select
while ( $row = mysqli_fetch_array($link, $result, MYSQL_ASSOC) ) {?>
  <option value="<?php echo $result['id']; ?>"><?php echo $result['name'] ?></option>
<?php}

// More code ommitted

if (isset($_GET['id'])) {
  $id = sanitise($_GET['id']); // I recommend creating a function for this,
                               // but if only you are going to use it, maybe
                               // don't bother.
  $result = mysqli_query($link, "SELECT * FROM users WHERE id = $id");
  // now create our form.

  if (isset($_POST['submit'])) {
    // data to be updated
    $data = sanitise($_POST['data']);
    // ...

    mysqli_query($link, "UPDATE users SET data = $data, ... WHERE id = $id");
    // To avoid the 'refresh to send data thing', you might want to do a
    // location header trick
    header('Location: user.php?id='.$id);
  }
}

これは私が話している考え方のほんの一例であり、多くのコードが省略されていることを覚えておいてください。私は通常、<?php ?>タグの外側に HTML を実際に書くのは好きではありませんが、うまくいくと思います。特に小さいものには。

于 2013-03-09T16:03:50.700 に答える