2009-06-30 9 views
1

ドロップダウン選択として機能する1つのMySQLテーブルからクライアント名のリストを取得しています。データは別のテーブルに格納されます。 2番目のテーブルのフィールドに割り当てられているクライアントがすでに存在する場合は、選択肢として選択するようにしたいと思います。phpのフォームの問題。動的に選択されたオプションとチェックボックス

また、私のラジオボタンは、間違ったフィールドにデータを入力しています。なぜこれが起こっているのでしょうか?

ご意見ありがとうございます。

以下のコード:

<?php 

if(isset($_GET['id'])) 
{ 
    $query = "SELECT * ". 
      "FROM studies ". 
      "WHERE id = '".$_GET['id']."'"; 

    $result = mysql_query($query) or die('Error : ' . mysql_error()); 
     list($id, $pagetitle, $title, $date, $copy, $outputs, $strategies, $client, $niche, $media, $thumbmedia, $newfieldtitle, $newfieldcontent) = mysql_fetch_array($result, MYSQL_NUM); 



} 

if(isset($_POST['update1'])) 
{ 
    $id = $_POST['id']; 
    $pagetitle = $_POST['pagetitle']; 
    $title = $_POST['title']; 
    $date = $_POST['date']; 
    $copy = $_POST['copy']; 
    $outputs = $_POST['outputs']; 
    $strategies = $_POST['strategies']; 
    $client = $_POST['client']; 
    $niche = $_POST['niche']; 
    $media = $_POST['media']; 
    $thumbmedia = $_POST['thumbmedia']; 
    $newfieldtitle = $_POST['newfieldtitle']; 
    $newfieldcontent = $_POST['newfieldcontent']; 

    if(!get_magic_quotes_gpc()) 
    { 
     $pagetitle = addslashes($pagetitle); 
     $title = addslashes($title); 
     $date = addslashes($date); 
     $copy = addslashes($copy); 
     $outputs = addslashes($outputs); 
     $strategies = addslashes($strategies); 
     $client = addslashes($client); 
     $niche = addslashes($niche); 
     $media = addslashes($media); 
     $thumbmedia = addslashes($thumbmedia); 
     $newfieldtitle = addslashes($newfieldtitle); 
     $newfieldcontent = addslashes($newfieldcontent); 

    } 

    // update the article in the database 
    $query = "UPDATE studies 
      SET pagetitle = '$pagetitle', title = '$title', date = '$date', copy = '$copy', outputs = '$outputs', strategies = '$strategies', client = '$client', niche = '$niche', media = '$media', thumbmedia = '$thumbmedia', newfieldtitle = '$newfieldtitle', newfieldcontent = '$newfieldcontent' ". 
     "WHERE id = '$id'"; 
    mysql_query($query) or die('Error : ' . mysql_error()); 

    // then remove the cached file 
    $cacheDir = dirname(__FILE__) . '/cache/'; 

    $cacheFile = $cacheDir . '_' . $_GET['id'] . '.html'; 

    @unlink($cacheFile); 

    // and remove the index.html too because the file list 
    // is changed 
    @unlink($cacheDir . 'index.html'); 

    echo "<b>Article '$title' updated</b>"; 

    // now we will display $title & content 
    // so strip out any slashes 
     $pagetitle = stripslashes($pagetitle); 
     $title = stripslashes($title); 
     $date = stripslashes($date); 
     $copy = stripslashes($copy); 
     $outputs = stripslashes($outputs); 
     $strategies = stripslashes($strategies); 
     $client = stripslashes($client); 
     $niche = stripslashes($niche); 
     $media = stripslashes($media); 
     $thumbmedia = stripslashes($thumbmedia); 
     $newfieldtitle = stripslashes($newfieldtitle); 
     $newfieldcontent = stripslashes($newfieldcontent); 

} 


?> 


<div class="container"> 
<form method="post"> 
<input type="hidden" name="id" value="<?php echo $id; ?>"> 

<p class="subheadsmall">Browser Title</p> 
<textarea cols="40" rows="1" class="box" name="pagetitle" id="editbox"><?php echo $pagetitle; ?></textarea> 


<p class="subheadsmall">Story Title</p> 
<textarea cols="40" rows="1" class="box" name="title" id="editbox"><?php echo $title; ?></textarea> 

<p class="subheadsmall">Date</p> 
<textarea cols="40" rows="1" class="box" name="date" id="editbox"><?php echo $date; ?></textarea> 

<p class="subheadsmall">Story</p> 
<textarea cols="80" rows="10" class="box" name="copy" id="editbox"><?php echo $copy; ?></textarea> 

<p class="subheadsmall">Outputs</p> 
<textarea cols="80" rows="10" class="box" name="outputs" id="editbox"><?php echo $outputs; ?></textarea> 

<p class="subheadsmall">Strategies</p> 


<p class="subheadsmall">Client</p> 
<select type="text" name="client"> 
    <option value="empty">Select a Client...</option> 
<?php 
      $result = mysql_query("SELECT * FROM clients"); 
       if (!$result) { 
        die("Database query failed: " . mysql_error()); 
       } 


while($row = mysql_fetch_array($result)) { 
    $clientlist = $row['name']; 
    $clientname = htmlspecialchars($row['name']); 


    if(isset($_POST['client'])){ 

    echo '<option value="' . $clientlist . '" selected="selected" >' . $clientname . '</option>' . '\n'; 
    } 
    else{ 
    echo '<option value="' . $clientlist . '" >' . $clientname . '</option>' . '\n'; 
} 
} 


?> 
</select> 

<?php 



echo '<p class="subheadsmall">Core Classification</p>'; 
echo '<input type="radio" name="niche" value="brand"' . ($niche == "brand" ? " checked=\"checked\"" : "") . ' >Brand</input>'; 
echo '<input type="radio" name="niche" value="marketing"' . ($niche == "marketing" ? " checked=\"checked\"" : "") . ' >Marketing</input>'; 
echo '<input type="radio" name="niche" value="communication"' . ($niche == "communication" ? " checked=\"checked\"" : "") . ' >Communication</input>'; 


?> 

<p class="subheadsmall">Add New Strategy</p> 
<textarea cols="40" rows="1" class="box" name="strategies" id="editbox"><?php echo $strategies; ?></textarea> 
+0

私は言いたいことが一つのことを持っている...「ID = ';?真の研究から削除」おっと... –

+0

これは私が思い付いたあなたの質問への回答はなく、いくつかの考えではありませんすぐにあなたのコードを読んだ後。それが助けるかもしれないと思った。 $ _POST変数に同じ関数を1つずつ適用する代わりに、array_map()を使用することをお勧めします。 (例:array_map( 'addslashes'、$ _POST);) また、未確認の$ _GET変数を最初のクエリで使用しています(引用符で囲む必要はありません)。あなたのIDが整数であることを確かめるためにintval()を使いたいかもしれません。 また、変数を出力する前に、htmlentites()を使用することもできます。 – Sylvain

答えて

1
  • あなたif(isset($_POST['client']))条件が全く$rowを参照していないので、すべてのオプションのすべてのオプションや偽のために真であるかのいずれかだろう。私はあなたがその文で$clientlist$_POST['client']を比較したい推測:

    if ($_POST['client'] == $clientlist) 
    
  • <input>要素はコンテンツが含まれていません。 <input type="radio">Label</input>ではなく、<input type="radio" /> Labelのラベルが入力タグの後に付いている必要があります。

+0

あなたの助けをありがとうございます、痛みをおかけして申し訳ありませんが、私は$ _POST ['client']と$ clientlistをどのように比較しますか? がありがとう、ありがとう! – user96828

関連する問題